adhocteam/pushup

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

llimllib opened this issue · 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:

pushup/main.go

Line 303 in 7b9ec07

if err := os.RemoveAll(b.outDir); err != nil {

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

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?

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

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

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?