Skip to content

Commit

Permalink
fix: avoid inconsistency when using relative paths in trashed file in…
Browse files Browse the repository at this point in the history
…fo. (#39)

We use absolute paths now without trying to generate a relative path
based on some top directory as the latter seems to be causing
inconsistencies on some linux distros, as the restore path ends
up being incorrect.

Rather go with the absolute truth and don't fiddle with path
transformations at all to make it work everywhere.
  • Loading branch information
Byron committed May 13, 2022
1 parent 50ab31a commit 367cf5f
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/freedesktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,10 @@ fn execute_on_mounted_trash_folders<F: FnMut(PathBuf) -> Result<(), Error>>(
fn move_to_trash(
src: impl AsRef<Path>,
trash_folder: impl AsRef<Path>,
topdir: impl AsRef<Path>,
_topdir: impl AsRef<Path>,
) -> Result<(), Error> {
let src = src.as_ref();
let trash_folder = trash_folder.as_ref();
let topdir = topdir.as_ref();
let root = Path::new("/");
let files_folder = trash_folder.join("files");
let info_folder = trash_folder.join("info");

Expand Down Expand Up @@ -417,15 +415,7 @@ fn move_to_trash(
writeln!(file, "[Trash Info]")
.and_then(|_| {
let absolute_uri = encode_uri_path(src);
let topdir_uri = encode_uri_path(topdir);
let relative_untrimmed = absolute_uri
.chars()
.skip(topdir_uri.chars().count())
.collect::<String>();
let relative_uri = relative_untrimmed.trim_start_matches('/');
let path =
if topdir == root { absolute_uri.as_str() } else { relative_uri };
writeln!(file, "Path={}", path).and_then(|_| {
writeln!(file, "Path={}", absolute_uri).and_then(|_| {
writeln!(file, "DeletionDate={}", now.format("%Y-%m-%dT%H:%M:%S"))
})
})
Expand Down

0 comments on commit 367cf5f

Please sign in to comment.