mirror of
https://github.com/narrrl/proton-drive-linux.git
synced 2026-11-22 18:33:31 +01:00
fix(trash): list a large trash, empty it, and browse it by folder
A large trash never finished listing, so the Trash page kept the rows of the last refresh that got anywhere, and Empty Trash listed the trash before sending the delete and hung there (B293). The paging fix is in proton-drive-rs 0.12.5. - The refresh reads only nodes it has not stored yet, without unlocking file keys, keeps the time the server says each was trashed, and drops rows only once the whole listing is in. - Empty Trash sends the delete at once under the trash call time limit and clears the stored listing. Restore and Delete Permanently drop their rows right away. - Schema v47 indexes trash.parent_uid and drops the stored rows once, so they are read again with real deletion times. - The Trash page groups items by the folder they were deleted from, opens deleted folders through the new ListTrashedFolder request, and has a search box and a switch back to one list. Restore and Delete Permanently on a folder row act on everything deleted from it. - pdfs trash takes --by-folder and --folder UID.
This commit is contained in:
1 parent
f141d88d97
commit
d0f9681593
30 files changed
+2661
-1306
No files matched your search
@@ -1,6 +1,6 @@
|
||||
//! `pdfs` — command-line front-end for the Proton Drive Linux client.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
use std::os::unix::fs::FileTypeExt;
|
||||
@@ -436,7 +436,14 @@ enum Command {
|
||||
Diagnostics,
|
||||
/// List what is in the account's trash, with the uids the restore and
|
||||
/// delete-forever commands take.
|
||||
Trash,
|
||||
Trash {
|
||||
/// Group the trash by the folder each item was deleted from.
|
||||
#[arg(long, conflicts_with = "folder")]
|
||||
by_folder: bool,
|
||||
/// List what a trashed folder holds, by its uid.
|
||||
#[arg(long, value_name = "UID")]
|
||||
folder: Option<String>,
|
||||
},
|
||||
/// Restore trashed items, by uid, to the folders they were trashed from.
|
||||
Restore {
|
||||
/// Node uids (`volume~link`), as printed by `pdfs trash`.
|
||||
@@ -1139,7 +1146,7 @@ fn main() -> Result<()> {
|
||||
Command::Upload { sources, parent } => cmd_upload(sources, parent),
|
||||
Command::Transfers => cmd_transfers(),
|
||||
Command::Diagnostics => cmd_diagnostics(),
|
||||
Command::Trash => cmd_trash(),
|
||||
Command::Trash { by_folder, folder } => cmd_trash(by_folder, folder),
|
||||
Command::Restore { uids } => cmd_restore(uids),
|
||||
Command::DeleteForever { uids } => cmd_delete_forever(uids),
|
||||
Command::EmptyTrash => cmd_empty_trash(),
|
||||
@@ -3617,17 +3624,37 @@ fn cmd_diagnostics() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn cmd_trash() -> Result<()> {
|
||||
let response = control_request(CtlRequest::ListTrash)?;
|
||||
fn cmd_trash(by_folder: bool, folder: Option<String>) -> Result<()> {
|
||||
let request = match folder {
|
||||
Some(uid) => CtlRequest::ListTrashedFolder { uid },
|
||||
None => CtlRequest::ListTrash,
|
||||
};
|
||||
let response = control_request(request)?;
|
||||
if emit_json(&response)? {
|
||||
return Ok(());
|
||||
}
|
||||
match response {
|
||||
CtlResponse::Entries { entries } if entries.is_empty() => println!("(trash is empty)"),
|
||||
CtlResponse::Entries { entries } if entries.is_empty() => println!("(nothing here)"),
|
||||
CtlResponse::Entries { entries } if by_folder => {
|
||||
let mut groups: BTreeMap<String, Vec<&pdfs_core::control::DirEntry>> = BTreeMap::new();
|
||||
for e in entries.iter().filter(|e| e.trashed_parent.is_none()) {
|
||||
let folder = match e.trashed_from.as_deref() {
|
||||
None => "(unknown folder)".to_string(),
|
||||
Some("") => "/".to_string(),
|
||||
Some(path) => format!("/{path}"),
|
||||
};
|
||||
groups.entry(folder).or_default().push(e);
|
||||
}
|
||||
for (folder, items) in groups {
|
||||
println!("{folder} ({} item(s))", items.len());
|
||||
for e in items {
|
||||
print_trashed(e, " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
CtlResponse::Entries { entries } => {
|
||||
for e in entries {
|
||||
let kind = if e.is_dir { "d" } else { "-" };
|
||||
println!("{kind} {:>12} {} [{}]", e.size, e.name, e.uid);
|
||||
for e in &entries {
|
||||
print_trashed(e, "");
|
||||
}
|
||||
}
|
||||
CtlResponse::Error { message, kind } => bail!("{}", cli_error(kind, &message)),
|
||||
@@ -3636,6 +3663,11 @@ fn cmd_trash() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_trashed(e: &pdfs_core::control::DirEntry, indent: &str) {
|
||||
let kind = if e.is_dir { "d" } else { "-" };
|
||||
println!("{indent}{kind} {:>12} {} [{}]", e.size, e.name, e.uid);
|
||||
}
|
||||
|
||||
fn cmd_restore(uids: Vec<String>) -> Result<()> {
|
||||
match control_request(CtlRequest::Restore { uids })? {
|
||||
CtlResponse::Ok { message } => println!("{message}"),
|
||||
@@ -5091,6 +5123,7 @@ mod login_wait_tests {
|
||||
shared_by_unverified: false,
|
||||
trashed_at: 0,
|
||||
trashed_from: None,
|
||||
trashed_parent: None,
|
||||
issue: None,
|
||||
};
|
||||
assert_eq!(shared_by_line(&entry), None, "no invitation, no line");
|
||||
|
||||
Reference in new issue
Block a user