From 2de850479101e5a378c87d1392ea03c63ce224cf Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 19 Aug 2003 09:04:47 +0000 Subject: [PATCH] * Delete the temporary directories of failed builds by default, and an option `--keep-failed' to override this behaviour. --- doc/manual/nix-reference.xml | 17 +++++++++++++++++ src/exec.cc | 6 +++++- src/globals.cc | 3 +++ src/globals.hh | 6 ++++++ src/nix-help.txt | 1 + src/nix.cc | 2 ++ 6 files changed, 34 insertions(+), 1 deletion(-) diff --git a/doc/manual/nix-reference.xml b/doc/manual/nix-reference.xml index 75009b1d0..d9c78ff07 100644 --- a/doc/manual/nix-reference.xml +++ b/doc/manual/nix-reference.xml @@ -15,6 +15,10 @@ + + + + operation options arguments @@ -121,6 +125,19 @@ + + + + + + Specifies that in case of a build failure, the temporary directory + (usually in /tmp) in which the build takes + place should not be deleted. The path of the build directory is + printed as an informational message. + + + + diff --git a/src/exec.cc b/src/exec.cc index d82f5effa..fdfb467cc 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -122,7 +122,11 @@ void runProgram(const string & program, throw Error("unable to wait for child"); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { - delTmpDir.cancel(); + if (keepFailed) { + msg(lvlTalkative, + format("build failed; keeping build directory `%1%'") % tmpDir); + delTmpDir.cancel(); + } throw Error("unable to build package"); } } diff --git a/src/globals.cc b/src/globals.cc index 1ec0c4f9b..f21820f59 100644 --- a/src/globals.cc +++ b/src/globals.cc @@ -17,6 +17,9 @@ string nixLogDir = "/UNINIT"; string nixDBPath = "/UNINIT"; +bool keepFailed = false; + + void openDB() { nixDB.open(nixDBPath); diff --git a/src/globals.hh b/src/globals.hh index 2c4d33920..107d617bc 100644 --- a/src/globals.hh +++ b/src/globals.hh @@ -69,6 +69,12 @@ extern string nixLogDir; extern string nixDBPath; +/* Misc. global flags. */ + +/* Whether to keep temporary directories of failed builds. */ +extern bool keepFailed; + + /* Open the database environment. */ void openDB(); diff --git a/src/nix-help.txt b/src/nix-help.txt index 0e54d162d..4e1d707c8 100644 --- a/src/nix-help.txt +++ b/src/nix-help.txt @@ -34,3 +34,4 @@ Query flags: Options: --verbose / -v: verbose operation (may be repeated) + --keep-failed / -K: keep temporary directories of failed builds diff --git a/src/nix.cc b/src/nix.cc index 4beeb5da8..704442c31 100644 --- a/src/nix.cc +++ b/src/nix.cc @@ -372,6 +372,8 @@ void run(Strings args) pathArgs = true; else if (arg == "--verbose" || arg == "-v") verbosity = (Verbosity) ((int) verbosity + 1); + else if (arg == "--keep-failed" || arg == "-K") + keepFailed = true; else if (arg == "--help") printHelp(); else if (arg[0] == '-')