Skip to content
New issue

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

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

Already on GitHub? # to your account

Removal of temporary files not working on Windows #2233

Open
Joerki opened this issue Nov 2, 2024 · 5 comments
Open

Removal of temporary files not working on Windows #2233

Joerki opened this issue Nov 2, 2024 · 5 comments
Labels
bug Something isn't working windows related to the windows ecosystem

Comments

@Joerki
Copy link

Joerki commented Nov 2, 2024

What happened:

Hi guys!

When I use grype with Git Bash on Windows grype has trouble to remove files and directories:

$ grype .
<some stuff about DB (no update needed) and scanned project>
[0000]  WARN no explicit name and version provided for directory source, deriving artifact ID from the given path (which is not ideal)
[0000] ERROR failed to remove file (C:\Users\joerki\AppData\Local\Temp\grype-db-listing974399563): %!w(string=remove C:\Users\joerki\AppData\Local\Temp\grype-db-list

(Yes, the filename seems to be incomplete)
Files and (empty) directories stay in temp directory. I see grype-db-listing* and grype-scratch* relics there. (* are several digits each)
I don't see this error when I use cmd.

What you expected to happen:

Grype erases temporary date even if (Git) Bash is used on Windows as shell.

How to reproduce it (as minimally and precisely as possible):

Use Git Bash instead of cmd for grype operations.

Anything else we need to know?:

Environment:

  • Output of grype version:

  • $ grype version
    Application: grype
    Version: 0.83.0
    BuildDate: 2024-10-28T21:54:11Z
    GitCommit: 0602464
    GitDescription: v0.83.0
    Platform: windows/amd64
    GoVersion: go1.23.2
    Compiler: gc
    Syft Version: v1.15.0
    Supported DB Schema: 5

  • OS (e.g: cat /etc/os-release or similar):
    Windows 11 23H2
    Git 2.47.0.2

@Joerki Joerki added the bug Something isn't working label Nov 2, 2024
@popey
Copy link
Contributor

popey commented Nov 3, 2024

Thanks for the issue report @Joerki and the steps to reproduce, that's very helpful.

I have reproduced the issue here on Windows 11 Home 22H3 with Git 2.47.0.windows.2

popey@DESKTOP-DDU38TO MINGW64 ~/Downloads
$ ./grype.exe db check -vvv
[0000]  INFO grype version: 0.83.0
[0000] DEBUG config:
  log:
      quiet: false
      level: trace
      file: ""
  dev:
      profile: none
  db:
      cache-dir: C:\Users\popey\AppData\Local\cache/grype/db
      update-url: https://toolbox-data.anchore.io/grype/databases/listing.json
      ca-cert: ""
      auto-update: true
      validate-by-hash-on-start: false
      validate-age: true
      max-allowed-built-age: 120h0m0s
      require-update-check: true
      update-available-timeout: 30s
      update-download-timeout: 5m0s
      max-update-check-frequency: 2h0m0s
[0000] DEBUG checking for available database updates
[0000] ERROR failed to remove file (C:\Users\popey\AppData\Local\Temp\grype-db-listing971526387): %!w(string=remove C:\Users\popey\AppData\Local\Temp\grype-db-listing971526387: The process cannot access the file because it is being used by another process.)
[0000] DEBUG found database update candidate: Listing(url=https://grype.anchore.io/databases/vulnerability-db_v5_2024-11-03T01:32:42Z_1730607684.tar.gz)
[0000] DEBUG existing database is already up to date
[0000] DEBUG no database update available
No update available
[0000] TRACE worker stopped component=eventloop
[0000] TRACE signal exit component=eventloop

popey@DESKTOP-DDU38TO MINGW64 ~/Downloads
$

@kzantow kzantow moved this to Ready in OSS Nov 27, 2024
@wagoodman wagoodman added windows related to the windows ecosystem and removed needs-investigation labels Nov 27, 2024
@jdanielp
Copy link

jdanielp commented Dec 3, 2024

FYI- I am also seeing this in Windows PowerShell running in Windows Terminal, Windows 10.

[0000] ERROR failed to remove file (C:\Users\JPIETK~1\AppData\Local\Temp\grype-db-listing388893059): %!w(string=remove C:\Users\JPIETK~1\AppData\Local\Temp\grype-db-listing388893059: The process cannot access the file because it is being used by another process.)

PowerShell version info ($PSVersionTable)":
image

Grype Version:
grype.exe --version
grype 0.84.0

If this is common to windows, I suggest renaming the issue to remove the "Git Bash" from the title or add "PowerShell".

@popey
Copy link
Contributor

popey commented Dec 3, 2024

@jdanielp Thanks for the confirmation. I have also managed to see this in a bog-standard Windows Command Prompt window on Windows 10, in a VM. So it's very much a Windows issue, and likely not Git Bash, you're right.

@popey popey changed the title Removal of temporary files not working with Git Bash on Windows Removal of temporary files not working on Windows Dec 3, 2024
@jdanielp
Copy link

jdanielp commented Dec 4, 2024

@popey If you need any help from me to test/verify/etc please let me know. It sounds like you have a reproducible environment but I'm happy to help if you need it.

@Dashtid
Copy link

Dashtid commented Dec 20, 2024

Don't know if it helps, but I am throwing in a bump here because I am running into exactly the same issue.
Although, I am using Powershell and not Git Bash.

Tried switching the temp file location to another customer location on my C-drive, but it still won't remove that listing file.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working windows related to the windows ecosystem
Projects
Status: Ready
Development

No branches or pull requests

6 participants