Restore into the path input, not the archive's embedded absolute path
Restore only used the path input for a redundant mkdir and then extracted to / using the absolute path baked into the archive, which pointed at the stale per-run workspace of whichever run saved it. Extract relative archives (<basename>/...) into the parent of the requested path; keep a legacy fallback (extract to /) for old archives, which report cache-hit only when the requested path actually gains content.
This commit is contained in:
+13
-1
@@ -40,7 +40,19 @@ runs:
|
||||
if [ -f "$ARCHIVE" ]; then
|
||||
echo "Cache hit: ${CACHE_KEY}"
|
||||
mkdir -p "$EXPANDED_PATH"
|
||||
if tar -xf "$ARCHIVE" -C "/" 2>/dev/null; then
|
||||
# New-format archives hold entries relative to the cached directory
|
||||
# (<basename>/...), so extract into the parent of the requested
|
||||
# path. Legacy archives embed the absolute path of the run that
|
||||
# saved them; fall back to extracting them to "/" (status quo,
|
||||
# they are TTL-pruned within the retention window anyway).
|
||||
FIRST_ENTRY=$(tar -tf "$ARCHIVE" 2>/dev/null | head -1)
|
||||
if [ "${FIRST_ENTRY%%/*}" = "$(basename "$EXPANDED_PATH")" ]; then
|
||||
echo "Restoring to: $(dirname "$EXPANDED_PATH")"
|
||||
tar -xf "$ARCHIVE" -C "$(dirname "$EXPANDED_PATH")" 2>/dev/null
|
||||
else
|
||||
tar -xf "$ARCHIVE" -C "/" 2>/dev/null
|
||||
fi
|
||||
if [ -d "$EXPANDED_PATH" ] && [ -n "$(ls -A "$EXPANDED_PATH" 2>/dev/null)" ]; then
|
||||
# record last use so the retention policy can expire by access time
|
||||
touch "$ARCHIVE"
|
||||
echo "cache-hit=true" >> $GITHUB_OUTPUT
|
||||
|
||||
Reference in New Issue
Block a user