pushup icon indicating copy to clipboard operation
pushup copied to clipboard

`go build -out-dir $(pwd)` will delete your working directory

Open llimllib opened this issue 3 years ago • 4 comments

Right now the first step in the build process is to delete everything in whatever directory you give it for an output directory, this is probably a footgun:

https://github.com/adhocteam/pushup/blob/7b9ec07d4ce06d3cf9fc9fc3d2e0bca92856ee2c/main.go#L303

Is there any reason to delete files other than ones that conflict with what pushup is building?

llimllib avatar Jan 09 '23 15:01 llimllib

Correct, it's intended to prevent accidental behavior such as a file generated from a previous run causing a Go compilation error.

What are the better approaches?

  • Build to a new temp dir each time and then atomically rename to the final path (rm'ing the old build dir at that point)
  • Removing only .up.go generated files before a build?

paulsmith avatar Jan 10 '23 23:01 paulsmith

What about this:

  • If the out-dir is an empty directory, proceed normally
  • otherwise, prompt the user if they really want to delete the directory
    • if y, delete it
    • if n, quit with a warning

llimllib avatar Jan 12 '23 15:01 llimllib

potentially with a --force-delete or similar option to allow the user to skip the warning; alternatively you could just leave it up to their responsibility to clear the directory before building if they don't want to receive the prompt

llimllib avatar Jan 12 '23 15:01 llimllib

in #83 we decided to aim for a nondestructive strategy rather than asking for permission to delete, which is not a great DX.

The next question is, how?

Given a build directory build, we want to build our app without interference from old versions of the app, and also without destroying all the files within (the current, "destructive" strategy).

A simple strategy would be:

  • On pushup build, create a GUID g and create a folder build/<g>, then build within that folder

That might ultimately create more files than are strictly necessary, but it's hard for me to see how we can safely re-use a directory that's already been used?

llimllib avatar Jan 14 '23 16:01 llimllib