]> err.no Git - dpkg/commitdiff
Dpkg::Exit and Dpkg::Source::Functions: two new modules
authorRaphael Hertzog <hertzog@debian.org>
Sun, 24 Feb 2008 20:56:16 +0000 (21:56 +0100)
committerRaphael Hertzog <hertzog@debian.org>
Sun, 24 Feb 2008 20:56:16 +0000 (21:56 +0100)
* 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 [new file with mode: 0644]
scripts/Dpkg/Source/Functions.pm [new file with mode: 0644]
scripts/Makefile.am
scripts/po/POTFILES.in

diff --git a/scripts/Dpkg/Exit.pm b/scripts/Dpkg/Exit.pm
new file mode 100644 (file)
index 0000000..7496407
--- /dev/null
@@ -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 (file)
index 0000000..d55c259
--- /dev/null
@@ -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;
index 0221ca6d1bba6c7129136718d8e695c436dcd518..71e12eb3c9320131171cf05609eef23c8415a69c 100644 (file)
@@ -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
index 20397e69f5eb2cab5a51ff41a5141dbcfd2c021f..7a7c71ff445361c00a67ee77b207e75c75d1e51e 100644 (file)
@@ -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