瀏覽代碼

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.
Raphael Hertzog 18 年之前
父節點
當前提交
2598aa3f12
共有 4 個文件被更改,包括 51 次插入0 次删除
  1. 17 0
      scripts/Dpkg/Exit.pm
  2. 31 0
      scripts/Dpkg/Source/Functions.pm
  3. 2 0
      scripts/Makefile.am
  4. 1 0
      scripts/po/POTFILES.in

+ 17 - 0
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;

+ 31 - 0
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;

+ 2 - 0
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

+ 1 - 0
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