cache icon indicating copy to clipboard operation
cache copied to clipboard

actions/cache/save can not handle circular symbolic links in saved paths (ELOOP: too many symbolic links encountered)

Open defanator opened this issue 1 year ago • 1 comments

The actions/cache/save@v4 action fails to create cache archive if there are "dead" circular symbolic links inside. The following error shows up in the output:

Warning: ELOOP: too many symbolic links encountered, stat '/home/runner/work/amneziawg-openwrt/amneziawg-openwrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/initial/lib/lib'
Warning: Cache save failed.

Problematic links:

$ find . -follow -printf ""
find: ‘./staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/mips-openwrt-linux-musl/lib/lib’: Too many levels of symbolic links
find: ‘./staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/initial/lib64/lib’: Too many levels of symbolic links
find: ‘./staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/initial/lib/lib’: Too many levels of symbolic links
find: ‘./staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/lib64/lib’: Too many levels of symbolic links
find: ‘./staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/lib32/lib’: Too many levels of symbolic links
find: ‘./staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/lib/lib’: Too many levels of symbolic links

All these are circular symlinks, e.g.:

lrwxrwxrwx 1 runner docker    3 Sep  7 19:56 lib -> lib
lrwxrwxrwx 1 runner docker 3 Sep  7 19:56 staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/initial/lib/lib -> lib

defanator avatar Sep 07 '24 21:09 defanator


name: Build and Cache with Symlink Handling

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      # Your build steps (example for OpenWrt context)
      - name: Build OpenWrt toolchain
        run: |
          # Simulate your build process that creates the toolchain and symlinks
          mkdir -p openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/initial/lib
          cd openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/initial/lib
          touch somefile
          ln -s lib lib  # Create the problematic circular symlink
          cd -
          echo "Build complete"

      # Preprocess: Remove or fix circular symlinks
      - name: Fix circular symlinks
        run: |
          # Find and remove self-referential symlinks
          find openwrt/staging_dir -type l -exec sh -c 'readlink "$1" | grep -q "^$(basename "$1")$" && rm -v "$1"' _ {} \;
          # Verify no circular symlinks remain
          echo "Checking for remaining issues:"
          find openwrt/staging_dir -follow -printf "" || echo "No issues found"

      # Save cache with cleaned-up directory
      - name: Save cache
        id: cache-save
        uses: actions/cache/save@v4
        with:
          path: |
            openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl
          key: Linux-${{ github.run_id }}-toolchain

      # Verify cache save success
      - name: Verify cache save
        run: |
          # Check if cache exists using GitHub API
          if ! gh api -H "Accept: application/vnd.github+json" \
            "/repos/${{ github.repository }}/actions/caches?key=Linux-${{ github.run_id }}-toolchain" | grep -q "cache_id"; then
            echo "Error: Cache save failed. No cache entry found."
            exit 1
          fi
          echo "Cache save verified successfully."
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

ljluestc avatar Mar 12 '25 16:03 ljluestc