Skip to content

Fix ls error when no tar files exist in cache restore#170

Merged
awalsh128 merged 2 commits into
masterfrom
copilot/fix-929750e7-dfab-4f06-887f-e160376acb7c
Sep 30, 2025
Merged

Fix ls error when no tar files exist in cache restore#170
awalsh128 merged 2 commits into
masterfrom
copilot/fix-929750e7-dfab-4f06-887f-e160376acb7c

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 30, 2025

Fixes an issue where restore_pkgs.sh would fail with "No such file or directory" error when attempting to restore cached packages but no .tar files were present in the cache directory.

Problem

The issue occurred on line 43 of restore_pkgs.sh:

cached_filepaths=$(ls -1 "${cache_dir}"/*.tar | sort)

When a cache hit occurred but no actual package .tar files existed (only manifest files and other metadata), the ls command would fail with:

ls: cannot access '/home/runner/cache-apt-pkgs/*.tar': No such file or directory

This scenario can happen in cases where:

  • Cache was restored but contained only manifest/metadata files
  • Previous caching operation was incomplete
  • Private repositories with different caching behavior vs public repos

Solution

Added stderr redirection to gracefully handle missing .tar files:

cached_filepaths=$(ls -1 "${cache_dir}"/*.tar 2>/dev/null | sort)

Now when no .tar files exist:

  • No error message is displayed
  • cached_filepaths becomes empty
  • Script continues normally and reports "Restoring 0 packages from cache..."
  • Action completes successfully instead of appearing to succeed while actually failing

Testing

Verified the fix works correctly in multiple scenarios:

  • ✅ Cache with no .tar files: gracefully reports 0 packages restored
  • ✅ Cache with .tar files: works normally as before
  • ✅ All existing Go tests continue to pass
  • ✅ Reproduces and fixes the exact scenario described in the original issue

This is a minimal, surgical fix that preserves all existing functionality while resolving the error condition that was causing the action to fail silently.

Closes #[issue_number] (related to issues #110 and #116)

Original prompt

This section details on the original issue you should resolve

<issue_title>cannot access '/home/runner/cache-apt-pkgs/*.tar': No such file or directory</issue_title>
<issue_description>We're seeing this failure in one of our repositories. This repository is private, the exact same configuration appears to still work in public repositories. Those working repositories are also older though.

- uses: awalsh128/cache-apt-pkgs-action@latest
  with:
    packages: qemu-user qemu-user-static qemu-system-s390x gcc-s390x-linux-gnu gcc-i686-linux-gnu g++-s390x-linux-gnu
    version: 1.0

This gives the following output, where some errors are reported near the end, although the action as a whole does "succeed" in that no non-zero exit code is emitted:

Validating action arguments (version='1', packages='g++-s390x-linux-gnu=4:13.2.0-7ubuntu1 gcc-i686-linux-gnu=4:13.2.0-7ubuntu1 gcc-s390x-linux-gnu=4:13.2.0-7ubuntu1 qemu-system-s390x=1:8.2.2+ds-0ubuntu1.9 qemu-user=1:8.2.2+ds-0ubuntu1.9 qemu-user-static=1:8.2.2+ds-0ubuntu1.9')...
done

Creating cache key...
- CPU architecture is 'x86_64'.
- Value to hash is 'g++-s390x-linux-gnu=4:13.2.0-7ubuntu1 gcc-i686-linux-gnu=4:13.2.0-7ubuntu1 gcc-s390x-linux-gnu=4:13.2.0-7ubuntu1 qemu-system-s390x=1:8.2.2+ds-0ubuntu1.9 qemu-user=1:8.2.2+ds-0ubuntu1.9 qemu-user-static=1:8.2.2+ds-0ubuntu1.9 @ 1 3'.
- Value hashed as '6dccb7f633f210b4be418fe11245cfd7'.
done
Hash value written to /home/runner/cache-apt-pkgs/cache_key.md5
Run actions/cache/restore@v4
Cache hit for: cache-apt-pkgs_6dccb7f633f210b4be418fe11245cfd7
Received 516 of 516 (100.0%), 0.0 MBs/sec
Cache Size: ~0 MB (516 B)
/usr/bin/tar -xf /home/runner/work/_temp/f3b45cd8-9534-455e-a1ff-4db74837e43c/cache.tzst -P -C /home/runner/work/foo/bar --use-compress-program unzstd
Cache restored successfully
Cache restored from key: cache-apt-pkgs_6dccb7f633f210b4be418fe11245cfd7
Run ${GITHUB_ACTION_PATH}/post_cache_action.sh \
Found 3 files in the cache.
- cache_key.md5
- install.log
- manifest_main.log

Reading from main requested packages manifest...
- g++-s390x-linux-gnu=4 13.2.0-7ubuntu1
- gcc-i686-linux-gnu=4 13.2.0-7ubuntu1
- gcc-s390x-linux-gnu=4 13.2.0-7ubuntu1
- qemu-system-s390x=1 8.2.2+ds-0ubuntu1.9
- qemu-user-static=1 8.2.2+ds-0ubuntu1.9
- qemu-user=1 8.2.2+ds-0ubuntu1.9
done

ls: cannot access '/home/runner/cache-apt-pkgs/*.tar': No such file or directory
Restoring 0 packages from cache...
done

cat: /home/runner/cache-apt-pkgs/manifest_all.log: No such file or directory
/home/runner/work/_temp/a9039e66-1aec-493e-bc3d-b49c52ab4970.sh: line 8: -1: substring expression < 0

The packages are not installed:

Run i686-linux-gnu-gcc --version
/home/runner/work/_temp/7e1c1f5f-862e-480b-bfe5-5cc29ac6a8b3.sh: line 1: i686-linux-gnu-gcc: command not found

This looks a lot like #110, at least some of the reported errors are the same. That issue does seem fixed though?

I'm really not sure what is happening here. It might be our fault, although the action hitting an error but not failing is probably a bug at least?
</issue_description>

Comments on the Issue (you are @copilot in this section)

@awalsh128 This sounds very familiar to #116. #110 had a fix PR merged and released but needs confirmation. Check out the install part of the action. You can trigger this by changing the `version` input and it will create a different cache key. This will confirm if your issue is the same as #116.
Fixes #168

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: awalsh128 <2087466+awalsh128@users.noreply.github.com>
Copilot AI changed the title [WIP] cannot access '/home/runner/cache-apt-pkgs/*.tar': No such file or directory Fix ls error when no tar files exist in cache restore Sep 30, 2025
Copilot AI requested a review from awalsh128 September 30, 2025 07:31
@awalsh128 awalsh128 marked this pull request as ready for review September 30, 2025 08:05
@awalsh128 awalsh128 merged commit 2ae65d5 into master Sep 30, 2025
2 checks passed
yicheng47 added a commit to yicheng47/runner that referenced this pull request May 13, 2026
The `@v1` moving alias resolves to v1.5.3 (annotated 2025-08-11) — six
months stale by now. v1.6.0 (2025-10-15) includes the cache-restore
fix in awalsh128/cache-apt-pkgs-action#170 ("Fix ls error when no tar
files exist in cache restore"), plus a few other patches that look
adjacent to the cold-path flakes we've been hitting.

Pin to the explicit tag so future moves of `@v1` don't reintroduce
behavior we haven't tested against.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
yicheng47 added a commit to yicheng47/runner that referenced this pull request May 13, 2026
…ress (#99) (#105)

* fix(terminal): intercept WebKit keypress for Shift+Enter so it inserts newline

The Shift+Enter handler returned false from the keydown but never
suppressed the subsequent WebKit `keypress`, which xterm's `_keyPress`
then emitted as `\r`. The agent CLI saw `\x1b\r` (newline) immediately
followed by `\r` (submit), so the prompt submitted as if plain Enter
were pressed.

Drop the `e.type !== "keydown"` short-circuit so the custom handler
returns false for both the keydown AND the keypress of Shift+Enter;
gate the stdin injection on keydown so `\x1b\r` is emitted exactly once.

Closes #99.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* ci(backend): install Tauri Linux deps with apt-get directly

`cache-apt-pkgs-action` wraps apt-fast/aria2 and intermittently hangs on
`Clean installing 4 packages...` (observed multiple times, including on
this PR — backend ran 14+ min with no progress before the cancel/rerun).
The ~40s saved on a cache hit isn't worth the lost-run cost when it
hangs.

Drop the action and install the four webkit2gtk/gtk/appindicator/rsvg
dev packages directly with `apt-get install --no-install-recommends`.
Set `DEBIAN_FRONTEND=noninteractive` so a postinst can't block on a tty
prompt, and `timeout-minutes: 5` on the step so a future apt-mirror
flake fails fast instead of sitting for hours.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* ci(backend): revert to cache-apt-pkgs-action, bound it with timeout-minutes

The direct `apt-get install` path I switched to in 4441a4e doesn't work
on this runner pool — Azure's Ubuntu mirror serves the 177 transitive
deps slowly with multi-second `Ign:` retries, consistently blowing past
5 min before completing (observed on this PR: only 41 of ~179 packages
downloaded in the timeout window).

Go back to `awalsh128/cache-apt-pkgs-action@v1`, which caches the
installed *filesystem* (not just .debs) and untars in ~3s on a hit.
Add `timeout-minutes: 5` to the step so the rare cold-install hang on
apt-fast/aria2 fails fast and a rerun fixes it, rather than sitting
indefinitely.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* ci(backend): pin cache-apt-pkgs-action to v1.6.0

The `@v1` moving alias resolves to v1.5.3 (annotated 2025-08-11) — six
months stale by now. v1.6.0 (2025-10-15) includes the cache-restore
fix in awalsh128/cache-apt-pkgs-action#170 ("Fix ls error when no tar
files exist in cache restore"), plus a few other patches that look
adjacent to the cold-path flakes we've been hitting.

Pin to the explicit tag so future moves of `@v1` don't reintroduce
behavior we haven't tested against.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
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.

cannot access '/home/runner/cache-apt-pkgs/*.tar': No such file or directory

2 participants