Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
llimllib opened this issue Jan 9, 2023 · 4 comments
Open

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

llimllib opened this issue Jan 9, 2023 · 4 comments

Comments

@llimllib
Copy link
Contributor

llimllib commented Jan 9, 2023

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?

@paulsmith
Copy link
Contributor

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?

@llimllib
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants