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

stack clean --full fails #5714

Closed
mpilgrem opened this issue Apr 15, 2022 · 0 comments
Closed

stack clean --full fails #5714

mpilgrem opened this issue Apr 15, 2022 · 0 comments

Comments

@mpilgrem
Copy link
Member

mpilgrem commented Apr 15, 2022

For both stack.exe version 2.7.5 and the current version (built at commit 403068f), as follows (on Windows 11 - but I do not think this is a Windows-specific problem, having found a solution):

❯ stack new cleanTest
Downloading template "new-template" to create project "cleanTest" in cleanTest\ ...
Looking for .cabal or package.yaml files to use to init the project.
Using cabal packages:
- cleanTest\

Selecting the best among 21 snapshots...

* Matches https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/3.yaml

Selected resolver: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/3.yaml
Initialising configuration using resolver: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/3.yaml
Total number of user packages considered: 1
Writing configuration to file: cleanTest\stack.yaml
All done.
C:\sr\templates\new-template.hsfiles:    6.06 KiB downloaded...
❯ cd cleanTest
❯ stack build
Building all executables for `cleanTest' once. After a successful build of all of them, only specified executables will be rebuilt.
cleanTest> configure (lib + exe)
Configuring cleanTest-0.1.0.0...
cleanTest> build (lib + exe)
Preprocessing library for cleanTest-0.1.0.0..
Building library for cleanTest-0.1.0.0..
[1 of 2] Compiling Lib
[2 of 2] Compiling Paths_cleanTest
Preprocessing executable 'cleanTest-exe' for cleanTest-0.1.0.0..
Building executable 'cleanTest-exe' for cleanTest-0.1.0.0..
[1 of 2] Compiling Main
[2 of 2] Compiling Paths_cleanTest
Linking .stack-work\dist\d53b6a14\build\cleanTest-exe\cleanTest-exe.exe ...
cleanTest> copy/register
Installing library in C:\Users\mikep\Documents\Code\Haskell\cleanTest\.stack-work\install\0fa84ff7\lib\x86_64-windows-ghc-9.0.2\cleanTest-0.1.0.0-GqaAHpw8uizcrM5mrfOeA
Installing executable cleanTest-exe in C:\Users\mikep\Documents\Code\Haskell\cleanTest\.stack-work\install\0fa84ff7\bin
Registering library for cleanTest-0.1.0.0..
❯ stack clean --full
Exception while recursively deleting C:\Users\mikep\Documents\Code\Haskell\cleanTest\.stack-work\
C:\Users\mikep\Documents\Code\Haskell\cleanTest\.stack-work\stack.sqlite3: removeDirectoryRecursive:removeContentsRecursive:removePathRecursive:DeleteFile "\\\\?\\C:\\Users\\mikep\\Documents\\Code\\Haskell\\cleanTest\\.stack-work\\stack.sqlite3": permission denied (The process cannot access the file because it is being used by another process.)
Perhaps you do not have permission to delete these files or they are in use?
Exception while recursively deleting C:\Users\mikep\Documents\Code\Haskell\cleanTest\.stack-work\
C:\Users\mikep\Documents\Code\Haskell\cleanTest\.stack-work\stack.sqlite3: removeDirectoryRecursive:removeContentsRecursive:removePathRecursive:DeleteFile "\\\\?\\C:\\Users\\mikep\\Documents\\Code\\Haskell\\cleanTest\\.stack-work\\stack.sqlite3": permission denied (The process cannot access the file because it is being used by another process.)
Perhaps you do not have permission to delete these files or they are in use?

--verbose also includes the following log:

2022-04-15 14:20:57.998144: [debug] Need to delete: ["C:\\Users\\mikep\\Documents\\Code\\Haskell\\cleanTest\\.stack-work\\","C:\\Users\\mikep\\Documents\\Code\\Haskell\\cleanTest\\.stack-work\\"]

which explains why the error message appears twice - the same folder is being listed twice for deletion.

There is no problem in deleting .stack-work in Explorer, so it may be stack clean --full is using the very file it seeks to delete.

@mpilgrem mpilgrem changed the title stack clean --full fails, on Windows 11 stack clean --full fails Apr 16, 2022
mpilgrem added a commit to mpilgrem/stack that referenced this issue Apr 16, 2022
…full` are not in use

The existing:
~~~
cleanCmd = withConfig NoReexec . withBuildConfig . clean
~~~
wraps `clean` in `withBuildConfig`, but that ends in `initProjectStorage projectStorageFile` and, so, uses one of the very files (`projectStorageFile`) that `stack clean -full` will attempt (and fail) to delete.

This pull request moves the `withBuildConfig` to wrap only the function that yields the list of files to be deleted (`dirsToDelete cleanOpts`), so that `projectStorageFile` is not in use when the file comes to be deleted.
mpilgrem added a commit that referenced this issue Apr 17, 2022
Fix #5714, so files to be deleted by `stack clean --full` are not in use
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant