haskell / hackage-security

Hackage security framework based on TUF (The Update Framework)
http://hackage.haskell.org/package/hackage-security
56 stars 47 forks source link

Unrelated withFile error message when renameFile errors #320

Open brandonchinn178 opened 2 months ago

brandonchinn178 commented 2 months ago

If I call downloadPackage' to a destination directory I haven't created yet, I get a weird error:

my-exe: /Users/bchinn/.cache/my-exe/package-index/hackage.haskell.org/01-index.tar: withFile: does not exist (No such file or directory)

This is weird because that filepath does exist.

Digging deeper, I found the issue occurs in the renameFile call. Because I didn't create the destination directory yet, renameFile errors with:

renameFile:renamePath:rename '/Users/bchinn/.cache/my-exe/package-index/hackage.haskell.org/Cabal-syntax-3.10.2.0.tar75518-0.gz' to '/Users/bchinn/.cache/my-exe/packages/Cabal-syntax-3.10.2.0': does not exist (No such file or directory)

But this error gets swallowed; presumably there's some clean up step that looks for 01-index.tar and errors before showing the actual error.

A few action items:

  1. Document that downloadPackage requires directory to exist (or create the directory automatically if it doesn't)
  2. Investigate why withFile complains about the file not existing when... it does?
  3. Check if the destination exists beforehand and show a better error message (contingent on how 1 and 2 get resolved)