Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.
Rust apple-notesapple-reminderscloudkitcrdtdesktop-appicloudicloud-calendaricloud-driveicloud-notesicloud-photosiphonelinuxlinux-desktoplocal-firstoffline-firstprivacyrusttauritauri-appwindows
Drive: a declined folder says so, and a name in use is refused up front
Yashwanth Kamireddid75918535dcf
diff --git a/.uiverify/assert.mjs b/.uiverify/assert.mjsindex b83b7fa..313f247 100644--- a/.uiverify/assert.mjs+++ b/.uiverify/assert.mjs@@ -67,7 +67,8 @@ await ctx.addInitScript(({ services }) => {return new Promise((resolve) => setTimeout(() => resolve(0), 250));}if (cmd === "drive_download") return "/home/user/Downloads/file.pdf";- if (cmd === "drive_create_folder" || cmd === "drive_rename" || cmd === "drive_delete" || cmd === "drive_move") return null;+ if (cmd === "drive_create_folder") { window.__folderCreates = (window.__folderCreates ?? 0) + 1; return null; }+ if (cmd === "drive_rename" || cmd === "drive_delete" || cmd === "drive_move") return null;if (cmd === "drive_item") return null;// One refresh for every service, and the event it finishes with.if (cmd === "sync_all" || cmd === "sync_status")@@ -283,6 +284,30 @@ let failures = 0;}+// ── Drive: a name already in the folder is refused before iCloud is asked ─────────────+// iCloud declines a second thing of the same name with a bare "UNKNOWN", which read as the+// folder having been made and then lost. Finder refuses it up front and says why; so does this.+{+ const page = await ctx.newPage();+ await page.goto("http://localhost:4173", { waitUntil: "networkidle" });+ await page.getByRole("button", { name: "iCloud Drive" }).click();+ await page.waitForSelector(".drive-rows");+ await page.getByRole("button", { name: "New Folder" }).click();+ await page.keyboard.type("downloads");+ await page.keyboard.press("Enter");+ await page.waitForTimeout(400);+ const creates = await page.evaluate(() => window.__folderCreates ?? 0);+ const said = await page.locator(".drive .error, [role=alert]").allInnerTexts();+ const refused = creates === 0 && said.some((t) => /already something called/.test(t));+ console.log(+ refused+ ? "PASS a name already in the folder is refused, and says so"+ : `FAIL a duplicate name sent ${creates} create(s), said ${JSON.stringify(said)}`+ );+ if (!refused) failures++;+ await page.close();+}+// ── Drive: a rapid double click must never duplicate the breadcrumb ────────────────────// The actual bug: an open() in flight let a second click on the same stale row append a// second identical crumb before the folder had finished loading — a trail that readdiff --git a/crates/quince-icloud/src/drive.rs b/crates/quince-icloud/src/drive.rsindex 6692d63..b639da1 100644--- a/crates/quince-icloud/src/drive.rs+++ b/crates/quince-icloud/src/drive.rs@@ -179,6 +179,27 @@ pub async fn download_to(Ok(())}+/// What a `createFolders` reply says happened.+///+/// Apple answers 200 either way. A folder it made comes back described, with `status: "OK"`;+/// one it declined comes back as the client id and a status alone — `UNKNOWN` for a name+/// already used in that folder, which is what a second submit of the same name produced. That+/// used to surface as "Apple created the folder but didn't describe it", which was false.+fn created_folder(body: &Value, name: &str) -> Result<DriveItem> {+ let folder = body+ .pointer("/folders/0")+ .ok_or_else(|| Error::Protocol("Drive's answer named no folder at all".into()))?;+ let status = folder.get("status").and_then(Value::as_str).unwrap_or("OK");+ if status != "OK" {+ return Err(Error::Protocol(format!(+ "iCloud Drive didn't create \u{201c}{name}\u{201d} ({status}). \+ Something with that name may already be here."+ )));+ }+ item_from(folder)+ .ok_or_else(|| Error::Protocol("Drive's answer described the folder without an id".into()))+}+/// Create a folder inside `parent_id`. Returns the item Apple stored.pub async fn create_folder(http: &reqwest::Client,@@ -213,9 +234,7 @@ pub async fn create_folder(let body: Value = serde_json::from_str(&text).map_err(|e| Error::Protocol(format!("Drive returned invalid JSON: {e}")))?;- body.pointer("/folders/0")- .and_then(item_from)- .ok_or_else(|| Error::Protocol("Apple created the folder but didn't describe it".into()))+ created_folder(&body, name)}/// The parent's own listing, straight from Apple — for finding an item's *current* etag@@ -418,6 +437,26 @@ pub async fn move_to(Ok(())}+#[cfg(test)]+mod created_folder_tests {+ use super::*;+ use serde_json::json;++ /// The two replies Apple gives, both measured: a made folder, and a second create of the+ /// same name.+ #[test]+ fn a_declined_folder_is_reported_as_declined() {+ let made = json!({ "folders": [{ "drivewsid": "FOLDER::com.apple.CloudDocs::A",+ "name": "Wallp", "type": "FOLDER", "status": "OK", "etag": "2y8" }] });+ assert_eq!(created_folder(&made, "Wallp").unwrap().name, "Wallp");++ let declined = json!({ "folders": [{ "clientId": "7222bf20", "status": "UNKNOWN" }] });+ let message = created_folder(&declined, "Wallp").unwrap_err().to_string();+ assert!(message.contains("didn't create"), "{message}");+ assert!(!message.contains("created the folder"), "{message}");+ }+}+#[cfg(test)]mod tests {use super::*;diff --git a/src/screens/DriveView.tsx b/src/screens/DriveView.tsxindex b93dc12..6627c6c 100644--- a/src/screens/DriveView.tsx+++ b/src/screens/DriveView.tsx@@ -266,19 +266,34 @@ export function DriveView() {};}, [upload, here.id]);+ /**+ * One folder per name typed. Enter submits, which closes the field, and closing it blurs+ * the field, which submitted again with the same name still in hand — Apple made the folder+ * the first time and declined the second, and the refusal was what showed.+ */+ const folderPending = useRef(false);const createFolder = useCallback(async () => {+ if (folderPending.current) return;const name = newFolderName.trim();setCreatingFolder(false);setNewFolderName("");if (!name) return;+ // Finder will not put two things of one name in a folder; neither will iCloud.+ if (items.some((i) => i.name.toLocaleLowerCase() === name.toLocaleLowerCase())) {+ setError(`There's already something called \u201c${name}\u201d here.`);+ return;+ }+ folderPending.current = true;setError(null);try {await api.driveCreateFolder(here.id, name);await refresh();} catch (e) {setError(messageOf(e));+ } finally {+ folderPending.current = false;}- }, [newFolderName, here.id, refresh]);+ }, [newFolderName, here.id, refresh, items]);return (<div className={`drive${dropping ? " is-dropping" : ""}`}>