Support `--dereference` when saving cache
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.9k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the enhancement
Sometimes the cache that is being tared contains symlinks that point to the nearby files or even files outside of the cached directory. The cache saves perfectly fine, but later when we attempt to restore such cache, it fails because it cannot create a symlink to the file that does not exist. It looks like this:
Attempting to restore external-python_3_10_x86_64-pc-windows-msvc cache from setup-bazel-1-win32-external-python_3_10_x86_64-pc-windows-msvc-6f4c09e6b71e9933f1f2aace478aa950ee73538fa85cce7bef10e24779d729f6
Received 36631515 of 36631515 (100.0%), 39.1 MBs/sec
Cache Size: ~35 MB (36631515 B)
C:\Windows\System32\tar.exe -z -xf D:/a/_temp/02921f51-e302-43b7-b3bb-f5d3a5f5a729/cache.tgz -P -C D:/a/selenium/selenium
../../../_bazel/external/python_3_10_x86_64-pc-windows-msvc/python: Can't create '\\\\?\\D:\\a\\selenium\\selenium\\..\\..\\..\\_bazel\\external\\python_3_10_x86_64-pc-windows-msvc\\python'
tar.exe: Error exit delayed from previous errors.
Warning: Failed to restore: Tar failed with error: The process 'C:\Windows\System32\tar.exe' failed with exit code 1
Failed to restore external-python_3_10_x86_64-pc-windows-msvc cache
Using GNU Tar is also not helpful, though an error is more explicit:
Attempting to restore external-python_3_9_x86_64-pc-windows-msvc cache from setup-bazel-1-win32-external-python_3_9_x86_64-pc-windows-msvc-6f4c09e6b71e9933f1f2aace478aa950ee73538fa85cce7bef10e24779d729f6
Received 35447681 of 35447681 (100.0%), 37.2 MBs/sec
Cache Size: ~34 MB (35447681 B)
"C:\Program Files\Git\usr\bin\tar.exe" --use-compress-program "zstd -d" -xf D:/a/_temp/75736ff4-aba8-4310-8874-c6d06ee98110/cache.tzst -P -C D:/a/selenium/selenium --force-local
/usr/bin/tar: ../../../_bazel/external/python_3_9_x86_64-pc-windows-msvc/python: Cannot create symlink to '/d/_bazel/external/python_3_9_x86_64-pc-windows-msvc/python.exe': No such file or directory
/usr/bin/tar: Exiting with failure status due to previous errors
Warning: Failed to restore: Tar failed with error: The process 'C:\Program Files\Git\usr\bin\tar.exe' failed with exit code 2
Failed to restore external-python_3_9_x86_64-pc-windows-msvc cache
The problem above happens because there is python symlink which points to python.exe in the same directory. However, since the file is not yet extracted, attempting to create a symlink to it fails.
tar has a flag --dereference which allows to follow symbolic links and copy linked files instead - https://ftp.gnu.org/old-gnu/Manuals/tar-1.12/html_node/tar_115.html. I think it would be nice if saveCache(...) supported a boolean flag dereferenceSymbolicLinks that would pass --dereference argument to tar.
Code Snippet
const cache = require('@actions/cache')
await cache.saveCache(['directory'], 'cache-key', { dereferenceSymbolicLinks: true })
Additional information
I can send PR adding this flag if this is something that you'd consider adding.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the saveCache(...) entry point and trace how the cache package constructs its tar command. Implement the dereferenceSymbolicLinks option and verify that enabling it passes --dereference while the default behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- devops
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100