Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Probe: live round trips for Drive Recently Deleted and Notes folders, throwaway data only

Yashwanth Kamireddi062f3372aa85
diff --git a/probe/examples/drive_trash_list.rs b/probe/examples/drive_trash_list.rs
new file mode 100644
index 0000000..8d40c31
--- /dev/null
+++ b/probe/examples/drive_trash_list.rs
@@ -0,0 +1,15 @@
+//! Live, read-only: what Drive's Recently Deleted holds, as Quince reads it.
+use anyhow::{anyhow, Result};
+#[tokio::main]
+async fn main() -> Result<()> {
+ let dir = std::path::PathBuf::from(std::env::var("HOME")?).join(".local/share/quince-probe");
+ let mut client = quince_auth::Client::new(&dir)?;
+ if !client.resume().await? { return Err(anyhow!("no session")); }
+ let root = client.session().service_url("drivews").ok_or_else(|| anyhow!("no drivews"))?;
+ let items = quince_icloud::drive::trash(client.http(), &root, client.service_params()).await?;
+ println!("{} in Recently Deleted", items.len());
+ for i in items.iter().take(5) {
+ println!(" {} | {} | {:?} | etag={:?} parent={:?}", i.drivewsid, i.display_name(), i.size, i.etag, i.parent_id);
+ }
+ Ok(())
+}
diff --git a/probe/examples/drive_trash_roundtrip.rs b/probe/examples/drive_trash_roundtrip.rs
new file mode 100644
index 0000000..c32a4ee
--- /dev/null
+++ b/probe/examples/drive_trash_roundtrip.rs
@@ -0,0 +1,33 @@
+//! Live, on the probe account, with a throwaway file only: upload, trash, recover, trash,
+//! delete for good — each step read back. Touches nothing that was there before.
+use anyhow::{anyhow, Result};
+#[tokio::main]
+async fn main() -> Result<()> {
+ let dir = std::path::PathBuf::from(std::env::var("HOME")?).join(".local/share/quince-probe");
+ let mut client = quince_auth::Client::new(&dir)?;
+ if !client.resume().await? { return Err(anyhow!("no session")); }
+ let drivews = client.session().service_url("drivews").ok_or_else(|| anyhow!("no drivews"))?;
+ let docws = client.session().service_url("docws").ok_or_else(|| anyhow!("no docws"))?;
+ let http = client.http().clone();
+ let p = client.service_params();
+ let tmp = std::env::temp_dir().join("quince-trash-test.txt");
+ std::fs::write(&tmp, b"Quince trash round trip. Safe to delete.")?;
+ let item = quince_icloud::drive::upload(&http, &docws, &drivews, p.clone(), quince_core::drive::ROOT, &tmp,
+ std::sync::Arc::new(|_, _| {})).await?;
+ println!("uploaded {}", item.drivewsid);
+ let in_trash = |id: String| { let (h, d, p) = (http.clone(), drivews.clone(), p.clone());
+ async move { Ok::<bool, anyhow::Error>(quince_icloud::drive::trash(&h, &d, p).await?.iter().any(|i| i.drivewsid == id)) } };
+ quince_icloud::drive::delete(&http, &drivews, p.clone(), &item).await?;
+ println!("trashed; in trash = {}", in_trash(item.drivewsid.clone()).await?);
+ quince_icloud::drive::put_back(&http, &drivews, p.clone(), &item).await?;
+ println!("recovered; in trash = {}", in_trash(item.drivewsid.clone()).await?);
+ // Re-read its etag where it landed, as Quince would after a refresh.
+ let mut lib = quince_core::Library::open(&std::env::temp_dir().join(format!("qtt-{}", uuid::Uuid::new_v4())))?;
+ quince_icloud::drive::sync_folder(&http, &drivews, p.clone(), &mut lib, quince_core::drive::ROOT).await?;
+ let back = lib.drive_item(&item.drivewsid)?.ok_or_else(|| anyhow!("not back in the root"))?;
+ println!("back in the root: {}", back.display_name());
+ quince_icloud::drive::delete(&http, &drivews, p.clone(), &back).await?;
+ quince_icloud::drive::delete_forever(&http, &drivews, p.clone(), &back).await?;
+ println!("deleted for good; in trash = {}", in_trash(item.drivewsid.clone()).await?);
+ Ok(())
+}