swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.74k stars 1.34k forks source link

Building a package creates a lock file in `AppData\Local\Temp` but never removes the lock file #8080

Open ahoppen opened 2 days ago

ahoppen commented 2 days ago

If you build a SwiftPM package on Windows, it creates a lock files for workspace-state.json and Package.resolved in a temporary directory but never deletes the lock file. On Unix systems, the lock files will eventually be cleaned up by the system removing files from the temporary directories but on Windows, AppData\Local\Temp does not get cleaned by the system (as far as I can tell) and the lock files stay around until the user manually removes them.

jakepetroules commented 1 day ago

%TEMP% is cleaned by Storage Sense in Windows 10/11, which runs automatically when disk space is low by default (a lot less often than the Unix counterpart), but can be adjusted to Daily, Weekly, or Monthly by the user.

Shall we close this?

ahoppen commented 1 day ago

I didn’t know about Storage Sense but I definitely ran my machine out of disk-space with files in Temp, gathering >200,000 temporary directories (might have been significantly more, that’s when it stopped counting) and rebooting didn’t fix it. Also, there was an issue about this in SourceKit-LSP (https://github.com/swiftlang/sourcekit-lsp/issues/1698). So, I think we can’t rely on Windows cleaning up Temp, like we do on Unix.

Related, swift-driver is leaking files as well: https://github.com/swiftlang/swift-driver/issues/1720