From a93fc1d9eecc435eea00b4ef5a6970183299d0be Mon Sep 17 00:00:00 2001 From: Joel <122166595+nalladev@users.noreply.github.com> Date: Thu, 16 Jul 2026 00:12:17 +0530 Subject: [PATCH] fix: fall back to GIO on destination open failure for MTP copies * fix: fall back to GIO on destination open failure for MTP copies * Preserve error source chain in non-gvfs open failure path --- src/operation/recursive.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/operation/recursive.rs b/src/operation/recursive.rs index a3bd2c4..f43e8bb 100644 --- a/src/operation/recursive.rs +++ b/src/operation/recursive.rs @@ -453,7 +453,7 @@ impl Op { } } - let (from_file, metadata, to_file) = cosmic::iced::futures::join!( + let (from_file_open_result, metadata, to_file_open_result) = cosmic::iced::futures::join!( async { compio::fs::OpenOptions::new() .read(true) @@ -469,12 +469,28 @@ impl Op { .write(true) .open(&self.to) .await - .with_context(|| format!("failed to open {} for writing", self.to.display())) } ); - let from_file = from_file?; - let mut to_file = to_file?; + let from_file = from_file_open_result?; + + let mut to_file = match to_file_open_result { + Ok(file) => file, + #[cfg(not(feature = "gvfs"))] + Err(why) => { + _ = from_file.close().await; + return Err(why).with_context(|| format!("failed to open {} for writing", self.to.display())).map_err(Into::into); + } + #[cfg(feature = "gvfs")] + Err(_why) => { + _ = from_file.close().await; + return self + .gio_file_copy(ctx, progress) + .await + .map(|()| true) + .map_err(Into::into); + } + }; progress.total_bytes = metadata.as_ref().map(|m| m.len()); (ctx.on_progress)(self, &progress);