Skip to content

storage: compare visited paths as folders, so x2 is staged after x (fslink, swift, s3) - #182

Open
rudolphpienaar wants to merge 2 commits into
masterfrom
fix/fslink-prefix-visited
Open

rudolphpienaar wants to merge 2 commits into
masterfrom
fix/fslink-prefix-visited

Conversation

@rudolphpienaar

@rudolphpienaar rudolphpienaar commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Bug

FSLinkStorage._find_all_file_paths skips a storage path when any(storage_path.startswith(p) for p in visited_paths). The comparison is on text, so once a ChRIS link to home/<user>/uploads/x has been followed, a link to home/<user>/uploads/x2 counts as already visited and its files are never fetched. BaseStorage._process_chrislink_files makes the same text comparison (link_file_path.startswith(p) for p in self._already_copied_src_set), and so do SwiftStorage and S3Storage in _find_all_storage_object_paths.

In 5.2.x/5.3.x the fslink expansion then fails with No such file or directory: …/incoming/home/<user>/uploads/x2 and CUBE cancels the job. On current master the failed copy is caught (except FileNotFoundError: pass), so the job runs without the x2 files instead of failing.

Swift and S3 list objects by name prefix, so listing x already returns the objects under x2 and their staged files were complete. The check was still wrong there: x2 was never visited and only arrived through that broader listing.

Found on a CUBE 6.11 + pfcon 5.2.4 deployment (in-network, STORAGE_ENV=fslink).

Fix

Add BaseStorage.is_path_under(path, root): true when path equals root or starts with root + '/' (trailing / on root ignored). All four checks use it:

  • pfcon/storage/base_storage.py: _process_chrislink_files
  • pfcon/storage/fslink_storage.py: _find_all_file_paths
  • pfcon/storage/swift_storage.py: _find_all_storage_object_paths
  • pfcon/storage/s3_storage.py: _find_all_storage_object_paths

A real descendant (x/sub after x) is still skipped as before. Nothing else changes. The other startswith calls in pfcon/storage/ are the job-output ancestor checks, which already compare with a trailing /.

Test

Each backend gets a unit test class next to its existing tests. The tests need no Docker, Swift or S3. Each one builds an input folder holding two .chrislink files, like pl-dircopy output, runs store_data (which calls process_chrislink_files) into a temporary job incoming dir, and checks the staged tree and nfiles.

  • tests/test_resources_fslink.py, TestFSLinkStorageStoreDataLinkedFolders, on a temporary storeBase:

    • x and x2: both folders staged. Fails before the fix (nfiles 1, x2 missing).
    • x1 and x2 (control): both staged, before and after.
    • x and x/sub (real nesting): x with sub/, plus x/sub on its own, before and after.
    • is_path_under on its own: equal, trailing slash, descendant, sibling x2, ancestor.

    os.walk is wrapped to return sorted names, so x.chrislink is always followed before x2.chrislink. Without that, directory order depends on the filesystem and the bug may not show.

  • tests/test_resources_swift.py, TestSwiftStorageStoreDataLinkedFolders, and tests/test_resources_s3.py, TestS3StorageStoreDataLinkedFolders, with an in-memory manager whose ls lists by name prefix like the real backends and records each prefix it is asked for:

    • x and x2: x2 is listed, and both folders are staged. Fails before the fix (x2 never listed).
    • x1 and x2 (control): both listed and staged, before and after.
    • x and x/sub: x/sub is not listed again after x, before and after.

Run locally without Docker:

pytest tests/test_resources_fslink.py::TestFSLinkStorageStoreDataLinkedFolders \
       tests/test_resources_fslink.py::TestFSLinkStorageGetDataSanitization \
       tests/test_resources_fslink.py::TestCopyWorkerExitOnFailure \
       tests/test_resources_swift.py::TestSwiftStorageStoreDataLinkedFolders \
       tests/test_resources_s3.py::TestS3StorageStoreDataLinkedFolders \
       tests/test_resources_mocked.py tests/compute

Fixes #180
Part of #181

…er x

FSLinkStorage._find_all_file_paths skipped any storage path that started,
as a string, with an already-visited path. After following a ChRIS link to
home/u/uploads/x, a link to home/u/uploads/x2 was treated as visited and
its files were never fetched into the job incoming dir.
BaseStorage._process_chrislink_files made the same string comparison
against the set of already-copied link sources.

Add BaseStorage.is_path_under, which treats a path as under a root only
when it equals the root or starts with the root plus '/', and use it in
both places. A real descendant (x/sub after x) is still skipped as before.

Fixes #180
SwiftStorage and S3Storage._find_all_storage_object_paths made the same
string-prefix visited check as FSLinkStorage, so after following a ChRIS
link to home/u/uploads/x a link to home/u/uploads/x2 was not visited. Use
BaseStorage.is_path_under there too.

Both backends list objects by name prefix, so listing x already returned
the objects under x2 and the staged files were complete. The check now
visits x2 itself instead of relying on that over-broad listing. The new
tests use an in-memory manager with the same prefix listing and assert
which prefixes are listed.
@rudolphpienaar rudolphpienaar changed the title fslink storage: compare visited paths as folders, so x2 is staged after x storage: compare visited paths as folders, so x2 is staged after x (fslink, swift, s3) Nov 15, 2026
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.

fslink storage skips a linked folder whose path extends an already-visited one (x then x2), cancelling the job

1 participant