Skip to content

Instantly share code, notes, and snippets.

@arbal
Forked from luckman212/icloud_ubiquity_fix.sh
Created May 13, 2025 18:04
Show Gist options
  • Select an option

  • Save arbal/1fb8de2d2fa035595d79f933d521da4a to your computer and use it in GitHub Desktop.

Select an option

Save arbal/1fb8de2d2fa035595d79f933d521da4a 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment