Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Error running with an empty cache dir: mkdir x file exists #122

Closed
marcellodesales opened this issue Jan 28, 2025 · 2 comments
Closed

Comments

@marcellodesales
Copy link
Contributor

marcellodesales commented Jan 28, 2025

I can't get to run a sync with a directory previously created from a Cache dir... The following error message is how it terminates...

Requirement

  • Cache the sync dir externally
    • That is, an initial empty dir is required to create the cache
    • The existing version fails to check for empty dir and create a cache file

Here's the error:

Caution

mkdir /var/tmp/codeqltmp: file exists\nCould not create cache directory.

🐊 Faulty Code?

We should have first a check if the directory exists and it's empty...

  • We are missing a check if it exists and it's empty, then we should skip the creation of the dir...

  • if isEmptyOrNonExistent {
    err := os.Mkdir(cacheDirectory.path, 0755)
    if err != nil {
    return errors.Wrap(err, "Could not create cache directory.")
    }
    err = ioutil.WriteFile(cacheVersionFilePath, []byte(version), 0644)
    if err != nil {
    return errors.Wrap(err, "Could not create cache version file.")
    }
    return nil
    }

🔧 Required Workflow

  • Since this is for using the remote cache, I'd like to prepare the local cache
    • That is, its creation is before the execution
    • The directory will be empty anyway
      - name: Create cache directory
        run: sudo mkdir -p ${{ env.CACHE_DIR }} && sudo chmod 777 ${{ env.CACHE_DIR }}

      - name: Restore cache
        uses: actions/cache@v4
        with:
          path: ${{ env.CACHE_DIR }}
          key: ${{ runner.os }}-codeql-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-codeql-
      - name: Run sync tool
        run: |
          ./codeql-action-sync sync \
            --cache-dir "${{ env.CACHE_DIR }}" \
            --destination-url "${{ env.GH_ENTERPRISE_URL }}" \
            --destination-repository ${{ inputs.githubOrRepo }} \
            --destination-token "${{ env.GH_ENTERPRISE_TOKEN }}"

💻 Logs

  • This is the error code trying to run it from actions
Run ./codeql-action-sync sync \
time="2025-01-28T20:22:55Z" level=info msg="Starting CodeQL Action sync tool version 1.0.11..."
time="2025-01-28T20:22:55Z" level=fatal msg="mkdir /var/tmp/codeqltmp: file exists\nCould not create cache directory.\ngithub.com/github/codeql-action-sync/internal/cachedirectory.(*CacheDirectory).CheckOrCreateVersionFile\n\t/home/runner/work/codeql-action-sync-tool/codeql-action-sync-tool/internal/cachedirectory/cachedirectory.go:87\ngithub.com/github/codeql-action-sync/internal/pull.Pull\n\t/home/runner/work/codeql-action-sync-tool/codeql-action-sync-tool/internal/pull/pull.go:264\ngithub.com/github/codeql-action-sync/cmd.glob..func4\n\t/home/runner/work/codeql-action-sync-tool/codeql-action-sync-tool/cmd/sync.go:17\ngithub.com/spf[13](https://git.viasat.com/seceng-devsecops-platform/vionix-platform-ghas-code_scanning_updater/actions/runs/2730506/job/10022602#step:8:14)/cobra.(*Command).execute\n\t/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:985\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\t/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1117\ngithub.com/spf13/cobra.(*Command).Execute\n\t/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1041\ngithub.com/spf13/cobra.(*Command).ExecuteContext\n\t/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1034\ngithub.com/github/codeql-action-sync/cmd.Execute\n\t/home/runner/work/codeql-action-sync-tool/codeql-action-sync-tool/cmd/root.go:76\nmain.main\n\t/home/runner/work/codeql-action-sync-tool/codeql-action-sync-tool/main.go:15\nruntime.main\n\t/opt/hostedtoolcache/go/1.21.6/x64/src/runtime/proc.go:267\nruntime.goexit\n\t/opt/hostedtoolcache/go/1.21.6/x64/src/runtime/asm_amd64.s:1650"
@marcellodesales marcellodesales changed the title Can't run sync tool from workflow job with cache: Can't run sync tool from workflow job with cache\ Jan 28, 2025
@marcellodesales marcellodesales changed the title Can't run sync tool from workflow job with cache\ 🐛 Can't run sync tool from workflow job with cache Jan 28, 2025
@marcellodesales marcellodesales changed the title 🐛 Can't run sync tool from workflow job with cache 🐛 Error when executing with an existing empty cache dir: mkdir /var/tmp/codeqltmp: file exists; Could not create cache directory Jan 29, 2025
@marcellodesales marcellodesales changed the title 🐛 Error when executing with an existing empty cache dir: mkdir /var/tmp/codeqltmp: file exists; Could not create cache directory 🐛 Error when executing with an existing empty cache dir: mkdir x file exists Jan 29, 2025
@marcellodesales marcellodesales changed the title 🐛 Error when executing with an existing empty cache dir: mkdir x file exists 🐛 Error running with an empty cache dir: mkdir x file exists; Could not create cache directory Jan 29, 2025
@marcellodesales marcellodesales changed the title 🐛 Error running with an empty cache dir: mkdir x file exists; Could not create cache directory 🐛 Error running with an empty cache dir: mkdir x file exists Jan 29, 2025
chrisgavin added a commit that referenced this issue Feb 4, 2025
…r-check

🐹 🐛 fix cachedirectory.go to allow an existing empty dir as cache
@marcellodesales
Copy link
Contributor Author

Hope to get this ticket verified after the PR #123 has been merged!

@chrisgavin
Copy link
Collaborator

Thanks for the fix here. It looks like it works.

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

No branches or pull requests

2 participants