Allow Trash to fallback to Delete on failure (#27682)

Conrad Irwin created

This fixes trashing files from the git panel on SSH remotes that don't
run a Desktop environment.

Release Notes:

- Fix trash to work on remotes with no desktop environment configured

Change summary

crates/fs/src/fs.rs | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

Detailed changes

crates/fs/src/fs.rs 🔗

@@ -453,7 +453,12 @@ impl Fs for RealFs {
         let file = smol::fs::File::open(path).await?;
         match trash::trash_file(&file.as_fd()).await {
             Ok(_) => Ok(()),
-            Err(err) => Err(anyhow::Error::new(err)),
+            Err(err) => {
+                log::error!("Failed to trash file: {}", err);
+                // Trashing files can fail if you don't have a trashing dbus service configured.
+                // In that case, delete the file directly instead.
+                return self.remove_file(path, RemoveOptions::default()).await;
+            }
         }
     }