diff options
author | qkzk <qu3nt1n@gmail.com> | 2022-12-27 15:48:11 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2022-12-27 15:48:11 +0100 |
commit | 3f93e99239776b6d5808a4c794a8734b92b185ed (patch) | |
tree | d8a4286c94a50d32b2cc9a6a403f535cd20861e7 | |
parent | 3b5d2ba7bbc77667b2f157dea28a842d4a193c1b (diff) |
encoding/decoding url, fix wrong path read
-rw-r--r-- | Cargo.lock | 16 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | development.md | 18 | ||||
-rw-r--r-- | src/trash.rs | 34 |
4 files changed, 48 insertions, 21 deletions
@@ -877,6 +877,7 @@ dependencies = [ "syntect", "sysinfo", "tuikit", + "url-escape", "users", ] @@ -1593,6 +1594,12 @@ dependencies = [ ] [[package]] +name = "percent-encoding" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" + +[[package]] name = "pin-project" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2662,6 +2669,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68" [[package]] +name = "url-escape" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44e0ce4d1246d075ca5abec4b41d33e87a6054d08e2366b63205665e950db218" +dependencies = [ + "percent-encoding", +] + +[[package]] name = "users" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -54,4 +54,5 @@ strum_macros = "0.24.3" syntect = "5.0.0" sysinfo = "0.26.7" tuikit = "0.4.5" +url-escape = "0.1.1" users = "0.11.0" diff --git a/development.md b/development.md index 6f19592..81ef0bc 100644 --- a/development.md +++ b/development.md @@ -244,6 +244,14 @@ ### Version 0.1.7 +- [x] Trash following [xdg trash](https://specifications.freedesktop.org/trash-spec/trashspec-latest.html) + + - [x] trahinfo + - [x] recreate parents if needed + - [x] allow multiple files with same name to be trashed + - [x] allow strange bytes in char + - [x] compatibiliy with other programs like trash-cli + ## TODO - [ ] remote control @@ -270,16 +278,6 @@ - [ ] navigable tree view [termtree](https://crates.io/crates/termtree) - [ ] zoxide support -### Version 0.1.7 - -- [ ] Trash following [xdg trash](https://specifications.freedesktop.org/trash-spec/trashspec-latest.html) - - - [x] trahinfo - - [x] recreate parents if needed - - [x] allow multiple files with same name to be trashed - - [x] allow strange bytes in char - - [ ] compatibiliy with other programs like trash-cli - - [ ] Version 0.2.0 : tests - [ ] tests diff --git a/src/trash.rs b/src/trash.rs index bd75854..9884e3c 100644 --- a/src/trash.rs +++ b/src/trash.rs @@ -44,11 +44,11 @@ impl TrashInfo { fn to_string(&self) -> FmResult<String> { Ok(format!( - "[TrashInfo] + "[Trash Info] Path={} DeletionDate={} ", - path_to_string(&self.origin)?, + url_escape::encode_fragment(path_to_string(&self.origin)?), self.deletion_date )) } @@ -91,7 +91,7 @@ DeletionDate={} if let Ok(lines) = read_lines(trash_info_file) { for (index, line_result) in lines.enumerate() { if let Ok(line) = line_result.as_ref() { - if line.starts_with("[TrashInfo]") { + if line.starts_with("[Trash Info]") { if index == 0 { found_trash_info_line = true; continue; @@ -103,7 +103,11 @@ DeletionDate={} if !found_trash_info_line { return trashinfo_error("Found Path line before TrashInfo"); } - let path_str = &line[6..]; + let path_part = &line[5..]; + info!("from_trash_info_file: encoded url {}", path_part); + let cow_path_str = url_escape::decode(path_part); + info!("from_trash_info_file: decoded url {}", cow_path_str); + let path_str = cow_path_str.as_ref(); option_path = Some(PathBuf::from(path_str)); } else if line.starts_with("DeletionDate=") && option_deleted_time.is_none() { @@ -121,11 +125,14 @@ DeletionDate={} } } match (option_path, option_deleted_time) { - (Some(origin), Some(deletion_date)) => Ok(Self { - dest_name, - deletion_date, - origin, - }), + (Some(origin), Some(deletion_date)) => { + info!("from_trash_info_file: {:?} parsed dest_name {} - deletion_date {} - origin {:?}", trash_info_file, dest_name, deletion_date, origin); + Ok(Self { + dest_name, + deletion_date, + origin, + }) + } _ => trashinfo_error("Couldn't parse the trash info file"), } } else { @@ -317,8 +324,13 @@ impl Trash { if !parent.exists() { std::fs::create_dir_all(&parent)? } - std::fs::rename(&trashed_file_content, &origin)?; - info!("trash: restored {:?} <- {:?}", origin, trashed_file_content); + match std::fs::rename(&trashed_file_content, &origin) { + Ok(()) => info!( + "trash restore: restored {:?} <- {:?}", + origin, trashed_file_content + ), + Err(e) => info!("trash restore: rename error {:?}", e), + } Ok(()) } |