haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.63k stars 697 forks source link

Support the CACHEDIR.TAG standard for dist and dist-newstyle #9529

Open Profpatsch opened 11 months ago

Profpatsch commented 11 months ago

Cache directories tend to be a nuisance for automatic backup tools, because they are very big, which steals network bandwidth and storage capacity from backups.

Users could manually add any Haskell project to their backup CLI with an absolute path, or they could add --exclude **/dist-newstyle and pray that no important information on their system uses the same directory name.

Or cabal could implement https://bford.info/cachedir/ and add a CACHEDIR.TAG file to its cache directories, meaning tools like tar --exclude-caches will ignore the directory.

Previous implementors of this spec I can see on my system (find . -iname "cachedir.tag"):

Basically every cache directory that’s not in /var/cache or under $XDG_CACHDIR should have this file.

Mikolaj commented 11 months ago

I sounds like a great idea to me. Possibly also important to industrial users (with limited resources). Does anybody see any problem with that or can we just mark it pr-welcome?

ulysses4ever commented 11 months ago

Sounds like a great idea to me!

Profpatsch commented 11 months ago

09·28 manofletters: So, after taking a quick look at the cabal source, it looks to me like most directories are created pretty ad-hoc whenever some subroutine needs them 09·29 with createDirectory/createDirectoryIfMissing/createDirectoryIfMissingVerbose 09·29 sometimes duplicated in multiple functions 09·30 I guess the least invasive change here is to add createCacheDirectory which ensures the tag file is there, and replace every createDirectory function that creates a cache directory with it 09·31 <&man_of_letters> Profpatsch: makes sense 09·31 ideally we’d check for the existence of a tag file as well every time 09·32 The standard has this weird thing that says “the program is responsible for making sure the cachedir.tag exists even if all files in the directory get deleted 09·32 But I think that’s not a good provision, cause it effectively means you have to check every time you access the directory, not just when you create it anew 09·32 So I’d ignore that 09·33 esp cause cabal itself deletes the whole directory on cabal clean anyway 09·33 we can check in createCacheDirIfMissing, that should be enough 09·39 <&man_of_letters> maybe they meant that you should add the tag file even if the directory is empty and keep it there even if it stays empty 09·39 <&man_of_letters> we "make sure" at creation time and then by not deleting it 09·40 <&man_of_letters> if a user subverts this by deleting the file manually, I don't think we should worry 09·40 <&man_of_letters> the user may have a valid reason 09·40 <&man_of_letters> so, agreed on that 09·51 yeah