Skip to content

fix: force fresh API fetch on readdir to surface new remote files - #4

Open
amlucas0xff wants to merge 1 commit into
ixs:masterfrom
amlucas0xff:fix/readdir-cache-invalidation
Open

fix: force fresh API fetch on readdir to surface new remote files#4
amlucas0xff wants to merge 1 commit into
ixs:masterfrom
amlucas0xff:fix/readdir-cache-invalidation

Conversation

@amlucas0xff

Copy link
Copy Markdown

Problem

Files added remotely (e.g. from an iOS device) never appear in a mounted iCloud Drive directory until the FUSE service is restarted.

Root Cause

pyicloud's DriveNode.get_children() maintains two layers of in-memory cache:

  1. self.data["items"] — raw API response, populated on first fetch
  2. self._children — parsed DriveNode objects built from data["items"]

get_children() only calls the API when "items" is absent from self.data. Once populated, both caches are never cleared, so the directory listing becomes permanently stale for the lifetime of the process.

Resetting only self._children is insufficient — it rebuilds children from the same stale data["items"] without making a new API call.

Fix

In readdir(), evict both cache layers before listing:

dh.data.pop("items", None)
dh._children = None

This forces get_children() to re-fetch directory contents from the iCloud API on every readdir call, so new files added remotely appear immediately on the next directory access without requiring a service restart.

Trade-off

Every directory listing now makes an API call. For typical interactive use (browsing, ls) this is acceptable. For high-frequency automated access, a TTL-based invalidation strategy would be preferable.

DriveNode.get_children() has two layers of in-memory cache:
- self.data["items"]: raw API response populated on first fetch
- self._children: parsed DriveNode objects built from data["items"]

Previously, neither was ever cleared. Files added remotely (e.g. from
iOS) would never appear in a mounted directory until the service
restarted, because get_children() skips the API call when "items" is
already present in self.data.

Clear both caches before listing in readdir() so every directory
listing fetches fresh data from the iCloud API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant