From 57b3004bde579b986523c43e3a0e6693fd49dd21 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 19 Aug 2011 10:06:00 +0100 Subject: [PATCH] febootstrap: Add --save-temps option to save temporary files on exit. --- .depend | 6 +++--- Makefile.am | 4 ++-- febootstrap.pod | 5 +++++ febootstrap_cmdline.ml | 6 ++++++ febootstrap_cmdline.mli | 3 +++ febootstrap_utils.ml | 12 ++++++++---- 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/.depend b/.depend index c42620f..e71f272 100644 --- a/.depend +++ b/.depend @@ -1,11 +1,11 @@ config.cmo: config.cmx: -febootstrap_utils.cmi: -febootstrap_utils.cmo: febootstrap_utils.cmi -febootstrap_utils.cmx: febootstrap_utils.cmi febootstrap_cmdline.cmi: febootstrap_cmdline.cmo: config.cmo febootstrap_cmdline.cmi febootstrap_cmdline.cmx: config.cmx febootstrap_cmdline.cmi +febootstrap_utils.cmi: +febootstrap_utils.cmo: febootstrap_cmdline.cmi febootstrap_utils.cmi +febootstrap_utils.cmx: febootstrap_cmdline.cmx febootstrap_utils.cmi febootstrap_package_handlers.cmi: febootstrap_package_handlers.cmo: febootstrap_utils.cmi \ febootstrap_cmdline.cmi febootstrap_package_handlers.cmi diff --git a/Makefile.am b/Makefile.am index 4765024..109d2c8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,10 +24,10 @@ SUBDIRS = lib helper # Note these must be in build dependency order. SOURCES = \ config.ml \ - febootstrap_utils.mli \ - febootstrap_utils.ml \ febootstrap_cmdline.mli \ febootstrap_cmdline.ml \ + febootstrap_utils.mli \ + febootstrap_utils.ml \ febootstrap_package_handlers.mli \ febootstrap_package_handlers.ml \ febootstrap_yum_rpm.ml \ diff --git a/febootstrap.pod b/febootstrap.pod index aa0a8cd..ac97f48 100644 --- a/febootstrap.pod +++ b/febootstrap.pod @@ -91,6 +91,11 @@ written (C and C). The default directory is the current directory. Note that if this files exist already in the output directory then they will be overwritten. +=item B<--save-temps> + +Don't remove temporary files and directories on exit. This is useful +for debugging. + =item B<-v> =item B<--verbose> diff --git a/febootstrap_cmdline.ml b/febootstrap_cmdline.ml index 902e313..667e297 100644 --- a/febootstrap_cmdline.ml +++ b/febootstrap_cmdline.ml @@ -22,6 +22,7 @@ let excludes = ref [] let names_mode = ref false let outputdir = ref "." let packages = ref [] +let save_temps = ref false let verbose = ref false let warnings = ref true let yum_config = ref None @@ -45,6 +46,10 @@ let argspec = Arg.align [ " Suppress warnings"; "-o", Arg.Set_string outputdir, "outputdir Set output directory (default: \".\")"; + "--save-temp", Arg.Set save_temps, + " Don't delete temporary files and directories on exit."; + "--save-temps", Arg.Set save_temps, + " Don't delete temporary files and directories on exit."; "-v", Arg.Set verbose, " Enable verbose output"; "--verbose", Arg.Set verbose, @@ -83,6 +88,7 @@ let excludes = List.rev !excludes let names_mode = !names_mode let outputdir = !outputdir let packages = List.rev !packages +let save_temps = !save_temps let verbose = !verbose let warnings = !warnings let yum_config = !yum_config diff --git a/febootstrap_cmdline.mli b/febootstrap_cmdline.mli index 107e70a..d948d80 100644 --- a/febootstrap_cmdline.mli +++ b/febootstrap_cmdline.mli @@ -35,6 +35,9 @@ val outputdir : string val packages : string list (** List of packages or package names as supplied on the command line. *) +val save_temps : bool + (** True if [--save-temps] was given on the command line. *) + val verbose : bool (** True if [--verbose] was given on the command line. See also {!debug}. *) diff --git a/febootstrap_utils.ml b/febootstrap_utils.ml index 04c91ad..2265753 100644 --- a/febootstrap_utils.ml +++ b/febootstrap_utils.ml @@ -90,10 +90,14 @@ let tmpdir () = *) let tmpdir = Filename.temp_dir_name // sprintf "febootstrap%s.tmp" data in Unix.mkdir tmpdir 0o700; - at_exit - (fun () -> - let cmd = sprintf "rm -rf %s" (Filename.quote tmpdir) in - ignore (Sys.command cmd)); + + (* Only remove the directory if --save-temps was *not* specified. *) + if not Febootstrap_cmdline.save_temps then + at_exit + (fun () -> + let cmd = sprintf "rm -rf %s" (Filename.quote tmpdir) in + ignore (Sys.command cmd)); + tmpdir let rec find s sub = -- 1.8.3.1