Files
openidea/crates/ide-remote/src/import.rs
l0ng-ai 5f57ce962e fix(project): import local files into remote project trees (#587)
Pasting or dropping OS files into a remote project tree sent a client-local source path to the server, so nothing was copied. Local-source imports are now carried separately from project copies and uploaded over the session SFTP channel: streamed in bounded chunks, created exclusively, cancellable across all selected paths under one task, with partial files removed on failure. Symlinks and Unix file modes are preserved, and special files are skipped and reported. Project-internal paste keeps working when the OS clipboard is briefly unavailable.

Native drop positions were assumed to be physical pixels, which shifted the target far from the pointer on Retina displays and with IDE zoom. A shared helper converts them to CSS coordinates for the project tree, the editor and Markdown drop handling, and the agent composer. Composer image drops are now read on the client in remote windows.

Verified on macOS against a live SSH host. Windows and Linux were not run: the Windows conversion is unchanged, the Linux one changed. Copy out from a remote tree to the local machine still needs a download workflow.
2026-11-01 00:14:56 +08:00

62 lines
2.1 KiB
Rust

//! Imports from the client filesystem into a remote project, without deployment mappings.
use ide_core::{CancellationToken, IdeError, IdeResult};
use ide_ssh::RemoteFs;
use std::path::Path;
/// Copies entries, preserving symlinks and empty folders. Reports skipped special files.
pub async fn import_local(fs: &RemoteFs, from: &Path, to: &str, cancel: &CancellationToken) -> IdeResult<Vec<String>> {
let mut skipped = Vec::new();
import_entry(fs, from, to, cancel, &mut skipped).await?;
Ok(skipped)
}
async fn import_entry(
fs: &RemoteFs,
from: &Path,
to: &str,
cancel: &CancellationToken,
skipped: &mut Vec<String>,
) -> IdeResult<()> {
if cancel.is_cancelled() {
return Err(IdeError::cancelled());
}
if fs.stat(to).await?.is_some() {
return Err(IdeError::new(ide_core::error::ErrorKind::AlreadyExists, format!("{to} already exists")));
}
let meta = tokio::fs::symlink_metadata(from).await?;
if meta.is_symlink() {
let result = async {
let target = tokio::fs::read_link(from).await?;
let target = target.to_str().ok_or_else(|| IdeError::invalid("Link target is not valid UTF-8"))?;
fs.symlink(target, to).await
}
.await;
if let Err(e) = result {
skipped.push(format!("{}: {e}", from.display()));
}
return Ok(());
}
if !meta.is_file() && !meta.is_dir() {
skipped.push(format!("{}: skipped special file", from.display()));
return Ok(());
}
if meta.is_file() {
return fs.upload_new(from, to, cancel).await;
}
fs.create_dir(to).await?;
let result = async {
let mut entries = tokio::fs::read_dir(from).await?;
while let Some(entry) = entries.next_entry().await? {
let name = entry.file_name();
let name = name.to_str().ok_or_else(|| IdeError::invalid("File name is not valid UTF-8"))?;
Box::pin(import_entry(fs, &entry.path(), &ide_ssh::sftp::join(to, name), cancel, skipped)).await?;
}
Ok(())
}
.await;
if result.is_err() {
let _ = fs.remove(to).await;
}
result
}