aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Thauvin <nanardon@mandriva.org>2004-12-14 00:02:26 +0000
committerOlivier Thauvin <nanardon@mandriva.org>2004-12-14 00:02:26 +0000
commit713e1c24d769bde79a146239ae324ccf74b31929 (patch)
tree4120f432ce69a2d1faf80ce9aa8098fafcb9d551
parent084f20aea7d3c6087593cc63ec603ae1741bd6ac (diff)
downloadrpmtools-713e1c24d769bde79a146239ae324ccf74b31929.tar
rpmtools-713e1c24d769bde79a146239ae324ccf74b31929.tar.gz
rpmtools-713e1c24d769bde79a146239ae324ccf74b31929.tar.bz2
rpmtools-713e1c24d769bde79a146239ae324ccf74b31929.tar.xz
rpmtools-713e1c24d769bde79a146239ae324ccf74b31929.zip
- don't use File::* modules
-rw-r--r--Packdrakeng.pm25
-rwxr-xr-xt/01packdrakeng.t16
2 files changed, 38 insertions, 3 deletions
diff --git a/Packdrakeng.pm b/Packdrakeng.pm
index 2e2b7a3..98956c6 100644
--- a/Packdrakeng.pm
+++ b/Packdrakeng.pm
@@ -19,14 +19,35 @@ package Packdrakeng;
use strict;
use warnings;
use POSIX qw(O_WRONLY O_TRUNC O_CREAT O_RDONLY);
-use File::Path;
-use File::Temp qw(tempfile);
(our $VERSION) = q$Id$ =~ /(\d+\.\d+)/;
my ($toc_header, $toc_footer) =
('cz[0', '0]cz');
+# File::Temp qw(tempfile) hack to not require it
+sub tempfile {
+ my ($count, $fname, $handle) = (0, undef, undef);
+ do {
+ ++$count > 10 and return (undef, undef);
+ $fname = sprintf("%s/packdrakeng.%s.%s",
+ $ENV{TMP} || '/tmp',
+ $$,
+ # Generating an random name
+ join("", map { $_=rand(51); $_ += $_ > 25 && $_ < 32 ? 91 : 65 ; chr($_) } (0 .. 4)));
+ } while ( ! sysopen($handle, $fname, O_WRONLY | O_APPEND | O_CREAT));
+ ($handle, $fname)
+}
+
+# File::Path hack to not require it
+sub mkpath {
+ my ($path) = @_;
+ $path =~ s:/*$::; # removing leading '/'
+ my $parent = substr($path, 0, length($path) - rindex($path, '/')+1);
+ -d $path and return 1;
+ -d $parent || mkpath($parent) or return 0;
+ mkdir($path);
+}
sub _new {
my ($class, %options) = @_;
diff --git a/t/01packdrakeng.t b/t/01packdrakeng.t
index fd0c3d6..6216dd5 100755
--- a/t/01packdrakeng.t
+++ b/t/01packdrakeng.t
@@ -3,7 +3,7 @@
# $Id$
use strict;
-use Test::More tests => 32;
+use Test::More tests => 37;
use Digest::MD5;
use_ok('Packdrakeng');
@@ -79,6 +79,20 @@ sub test_packing {
$pack = undef;
}
+# Testing simple additionnal function:
+clean_test_files();
+
+{
+my ($handle, $filename) = Packdrakeng::tempfile();
+ok($handle && $filename, "can create temp file");
+ok(-f $filename, "Temp file exist");
+ok(print($handle $coin), "can write into file");
+close($handle);
+unlink($filename);
+
+ok(Packdrakeng::mkpath('test/parent/child'), "can create dir like mkdir -p");
+ok(-d 'test/parent/child', "the dir really exist");
+}
# Single test:
{