Cabal creates files it can't remove?

I am getting an unusual error from Cabal.
I am on Windows Subsystem for Linux, it is Ubuntu 22.04 running on Windows 11.

I have never written any Haskell. I followed some online tutorials to create a new project. I used cabal init to create the cabal project.

I have ghc version 9.8.2, cabal-install version 3.10.3.0. Everything was installed with ghcup.

If I use

build-depends:
            base ^>=4.19.1.0

Cabal builds my program correctly and prints “Hello, world!”

When I modify this to

build-depends:
            base ^>=4.19.1.0,
            Frames ^>=0.7.4.2

I get an unusual error.

Resolving dependencies...
Build profile: -w ghc-9.8.2 -O1
In order, the following will be built (use -v for more details):
 - bifunctors-5.6.2 (lib) (requires build)
 - hashable-1.4.4.0 (lib) (requires build)
 - stringsearch-0.3.6.6 (lib:stringsearch) (requires build)
 - vinyl-0.14.3 (lib) (requires build)
 - profunctors-5.6.2 (lib) (requires build)
 - unordered-containers-0.2.20 (lib) (requires build)
 - discrimination-0.5 (lib) (requires build)
 - semigroupoids-6.0.0.1 (lib) (requires build)
 - free-5.2 (lib) (requires build)
 - pipes-group-1.0.12 (lib) (requires build)
 - pipes-bytestring-2.1.7 (lib) (requires build)
 - Frames-0.7.4.2 (lib) (requires build)
 - Analyses2-0.1.0.0 (exe:wnn) (configuration changed)
Starting     stringsearch-0.3.6.6 (all, legacy fallback)
Starting     bifunctors-5.6.2 (lib)
Starting     hashable-1.4.4.0 (lib)
Starting     vinyl-0.14.3 (lib)
Building     stringsearch-0.3.6.6 (all, legacy fallback)
Building     bifunctors-5.6.2 (lib)
Building     hashable-1.4.4.0 (lib)
Building     vinyl-0.14.3 (lib)
Installing   hashable-1.4.4.0 (lib)
Completed    hashable-1.4.4.0 (lib)
/mnt/d/.../Analyses2/dist-newstyle/tmp/src-23385/hashable-1.4.4.0: removeDirectoryRecursive:removeContentsRecursive:removePathRecursive:removeContentsRecursive:removeDirectory: permission denied (Permission denied)

I can repeat this with minor differences and different packages raise an error with removeDirectory, for example not hashable but th-abstraction instead.

The files that Cabal creates to populate the folder dist-newstyle/tmp appear to behave in a strange way with respect to filesystem permissions which I don’t know how to interpret. I ran rm -rf tmp and I got the following errors

rm -rf dist-newstyle/tmp/
rm: cannot remove 'dist-newstyle/tmp/src-23384/bifunctors-5.6.2/dist/build/autogen': Permission denied
rm: cannot remove 'dist-newstyle/tmp/src-23384/bifunctors-5.6.2/dist/build/Data/Bifunctor': Permission denied
rm: cannot remove 'dist-newstyle/tmp/src-23386/stringsearch-0.3.6.6/Data/ByteString/Lazy': Permission denied
rm: cannot remove 'dist-newstyle/tmp/src-23387/vinyl-0.14.3/Data/Vinyl/ARec': Permission denied

If I navigate to these folders after the command they are empty.
If I run rm -rf dist-newstyle/tmp again a second time, the files disappear, the filesystem having apparently changed its mind about whether I have permission to delete them.

If I try using sudo, I still get the same errors about not having permissions

rm: cannot remove 'dist-newstyle/tmp/src-23384/bifunctors-5.6.2': Permission denied
rm: cannot remove 'dist-newstyle/tmp/src-24596/bifunctors-5.6.2/dist/build/Data': Permission denied
rm: cannot remove 'dist-newstyle/tmp/src-24596/bifunctors-5.6.2/src/Data': Permission denied
rm: cannot remove 'dist-newstyle/tmp/src-24598/unordered-containers-0.2.20/dist/build/Data/HashMap': Permission denied
rm: cannot remove 'dist-newstyle/tmp/src-24599/vinyl-0.14.3/Data/Vinyl': Permission denied
rm: cannot remove 'dist-newstyle/tmp/src-24599/vinyl-0.14.3/dist/build/Data': Permission denied
rm: cannot remove 'dist-newstyle/tmp/src-24600/stringsearch-0.3.6.6/Data/ByteString/Lazy': Permission denied

but with a slightly different set of files.
If I run sudo rm -rf dist-newstyle/tmp again, it deletes some of the inner folders and raises new errors about being unable to delete the outer folders

rm: cannot remove 'dist-newstyle/tmp/src-24598/unordered-containers-0.2.20/dist/build': Permission denied
rm: cannot remove 'dist-newstyle/tmp/src-24599': Permission denied
rm: cannot remove 'dist-newstyle/tmp/src-24600/stringsearch-0.3.6.6': Permission denied

And every time I run the command it seems to prune folders from the bottom of the tree and return an error on the interior nodes? One more time, sudo rm -rf ./dist-newstyle/tmp

rm: cannot remove 'dist-newstyle/tmp/': Permission denied

Then, running it a fourth time, it is successful.

What is going on here? Cabal appears to be interacting in a very subtle and bizarre way with the file system permissions on WSL.

Maybe the problem is with WSL and not Cabal at all. The files are stored on /mnt/d/..., maybe it’s the fact that it’s interacting with a mounted drive with a Windows filesystem configuration?

1 Like

Files from Windows are accessed through a network file system under WSL. And they are subject to Windows file rules. This means if a program (likely an antivirus or file system indexer) has those files open they cannot be deleted!

To work around this store files under the Linux filesystem

4 Likes

Thanks. That makes sense. One point of confusion I have is that we can access files in the WSL linux filesystem transparently through the File Explorer in Windows, so I can open up /home/patn/myfile.txt in Notepad etc. So it’s not clear to me how to distinguish between files that are living on the Windows filesystem or the Linux filesystem.

This was it. I had Dropbox tracking the files in that directory. I paused Dropbox syncing and it compiled.
:smile: :sunny:

I will continue to store the files on the Windows filesystem, I will just pause Dropbox syncing and only sync it intermittently.

4 Likes