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.
I'd love to see this feature - working with an npm monorepo, I transpile packages on prepare, but the transpiled code is never cached, so I have to re-run the transpilation every time.
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:
Using GNU Tar is also not helpful, though an error is more explicit:
The problem above happens because there is
python
symlink which points topython.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 ifsaveCache(...)
supported a boolean flagdereferenceSymbolicLinks
that would pass--dereference
argument totar
.Code Snippet
Additional information
I can send PR adding this flag if this is something that you'd consider adding.