Skip to content

Instantly share code, notes, and snippets.

@luckman212
Created October 9, 2023 17:28
Show Gist options
  • Save luckman212/7afe50d37aa79d0170e8e96da2b96ae1 to your computer and use it in GitHub Desktop.
Save luckman212/7afe50d37aa79d0170e8e96da2b96ae1 to your computer and use it in GitHub Desktop.
Fix for stuck iCloud Ubiquity containers reported as Client Truth Client Truth Unclean Items
#!/usr/bin/env bash
CLIENT_DB="$HOME/Library/Application Support/CloudDocs/session/db/client.db"
[[ -e $CLIENT_DB ]] || { echo "db not found"; exit 1; }
mapfile -t ITEM_IDS < <(sqlite3 "$CLIENT_DB" <<-EOS
SELECT throttle_id
FROM client_sync_up
EOS
)
STUCKITEMCOUNT=${#ITEM_IDS[@]}
(( STUCKITEMCOUNT > 0 )) || { echo "no stuck items found"; exit 0; }
echo "found ${STUCKITEMCOUNT} stuck items"
CANARY_FNAME="flag_$(xxd -l3 -ps -c0 /dev/urandom)"
ID_STR=$(IFS=,; echo "${ITEM_IDS[*]}")
while IFS='|' read -r LIBRARY_NAME FNAME SESS_DIR _ ; do
FNAME=${FNAME/\~/$HOME}
SESS_DIR=${SESS_DIR/\~/$HOME}
if [[ -d $FNAME ]]; then
echo "writing canary file to $FNAME"
echo "xyzzy" >"$FNAME/$CANARY_FNAME"
else
echo "updating timestamp of $FNAME"
touch -A "$FNAME"
fi
done < <(sqlite3 "$CLIENT_DB" <<-EOS
SELECT
l.app_library_name,
'~/Library/Mobile Documents/' || REPLACE(l.app_library_name, '.', '~') || '/' || ci.item_filename,
'~/Library/Application Support/CloudDocs/session/containers/' || l.app_library_name
FROM
client_items as ci
INNER JOIN
app_libraries as l on ci.app_library_rowid = l.rowid
WHERE
ci.rowid IN ( $ID_STR )
ORDER BY
l.app_library_name
EOS
)
echo "pausing 10s to allow for stabilization"
sleep 10
echo "deleting flag/canary files ($CANARY_FNAME)"
find "$HOME/Library/Mobile Documents" -type f -name "$CANARY_FNAME" -delete
echo "done. please run \`brctl status\` again to re-check"
@luckman212
Copy link
Author

Workaround for iCloud bug described at https://apple.stackexchange.com/questions/465092/why-does-brctl-say-that-i-have-136-client-truth-unclean-items-unsynced-files

To use

  1. download
  2. make executable with chmod +x icloud_ubiquity_fix.sh
  3. execute with ./icloud_ubiquity_fix.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment