From 2598aa3f12c06d5838d91a007dcf13260631de57 Mon Sep 17 00:00:00 2001 From: Raphael Hertzog Date: Sun, 24 Feb 2008 21:56:16 +0100 Subject: [PATCH] Dpkg::Exit and Dpkg::Source::Functions: two new modules * scripts/Dpkg/Exit.pm: Enable to register some exit handlers that are called when a script is interrupted by a signal. * scripts/Dpkg/Source/Functions.pm: Contains some generic functions used by other Dpkg::Source::* modules. Only erasedir() for now. --- scripts/Dpkg/Exit.pm | 17 +++++++++++++++++ scripts/Dpkg/Source/Functions.pm | 31 +++++++++++++++++++++++++++++++ scripts/Makefile.am | 2 ++ scripts/po/POTFILES.in | 1 + 4 files changed, 51 insertions(+) create mode 100644 scripts/Dpkg/Exit.pm create mode 100644 scripts/Dpkg/Source/Functions.pm diff --git a/scripts/Dpkg/Exit.pm b/scripts/Dpkg/Exit.pm new file mode 100644 index 00000000..74964078 --- /dev/null +++ b/scripts/Dpkg/Exit.pm @@ -0,0 +1,17 @@ +package Dpkg::Exit; + +use strict; +use warnings; + +our @handlers = (); +sub exit_handler { + &$_() foreach (reverse @handlers); + exit(127); +} + +$SIG{'INT'} = \&exit_handler; +$SIG{'HUP'} = \&exit_handler; +$SIG{'QUIT'} = \&exit_handler; + +# vim: set et sw=4 ts=8 +1; diff --git a/scripts/Dpkg/Source/Functions.pm b/scripts/Dpkg/Source/Functions.pm new file mode 100644 index 00000000..d55c2592 --- /dev/null +++ b/scripts/Dpkg/Source/Functions.pm @@ -0,0 +1,31 @@ +package Dpkg::Source::Functions; + +use strict; +use warnings; + +use Exporter; +our @ISA = qw(Exporter); +our @EXPORT_OK = qw(erasedir); + +use Dpkg::ErrorHandling qw(syserr subprocerr failure); +use Dpkg::Gettext; + +use POSIX; + +sub erasedir { + my ($dir) = @_; + if (not lstat($dir)) { + return if $! == ENOENT; + syserr(_g("cannot stat directory %s (before removal)"), $dir); + } + system 'rm','-rf','--',$dir; + subprocerr("rm -rf $dir") if $?; + if (not stat($dir)) { + return if $! == ENOENT; + syserr(_g("unable to check for removal of dir `%s'"), $dir); + } + failure(_g("rm -rf failed to remove `%s'"), $dir); +} + +# vim: set et sw=4 ts=8 +1; diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 0221ca6d..71e12eb3 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -95,6 +95,7 @@ nobase_dist_perllib_DATA = \ Dpkg/Control.pm \ Dpkg/Deps.pm \ Dpkg/ErrorHandling.pm \ + Dpkg/Exit.pm \ Dpkg/Fields.pm \ Dpkg/Gettext.pm \ Dpkg/IPC.pm \ @@ -108,6 +109,7 @@ nobase_dist_perllib_DATA = \ Dpkg/Source/Archive.pm \ Dpkg/Source/CompressedFile.pm \ Dpkg/Source/Compressor.pm \ + Dpkg/Source/Functions.pm \ Dpkg/Source/Patch.pm \ Dpkg/Source/VCS/git.pm \ Dpkg.pm diff --git a/scripts/po/POTFILES.in b/scripts/po/POTFILES.in index 20397e69..7a7c71ff 100644 --- a/scripts/po/POTFILES.in +++ b/scripts/po/POTFILES.in @@ -30,6 +30,7 @@ scripts/Dpkg/Shlibs/SymbolFile.pm scripts/Dpkg/Source/Archive.pm scripts/Dpkg/Source/CompressedFile.pm scripts/Dpkg/Source/Compressor.pm +scripts/Dpkg/Source/Functions.pm scripts/Dpkg/Source/Patch.pm scripts/Dpkg/Source/VCS/git.pm scripts/Dpkg/Substvars.pm -- 2.39.5