From 0977b27affca5e32b01cfab810f8ca5919691c0c Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Mon, 7 Jul 2008 13:40:23 +0000 Subject: create file2absolute_file() and use it --- urpm/args.pm | 6 ++++-- urpm/util.pm | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/urpm/args.pm b/urpm/args.pm index 903ab2b2..54013793 100644 --- a/urpm/args.pm +++ b/urpm/args.pm @@ -8,6 +8,7 @@ no warnings 'once'; use Getopt::Long;# 2.33; use urpm::download; use urpm::msg; +use urpm::util 'file2absolute_file'; use Exporter; our @ISA = 'Exporter'; @@ -461,8 +462,9 @@ foreach my $k ("help|h", "version") { sub set_root { my ($urpm, $root) = @_; - require File::Spec; - $urpm->{root} = File::Spec->rel2abs($root); + + $urpm->{root} = file2absolute_file($root); + if (!-d $urpm->{root}) { $urpm->{fatal}->(9, N("chroot directory doesn't exist")); } diff --git a/urpm/util.pm b/urpm/util.pm index 09b20467..4c51d2ff 100644 --- a/urpm/util.pm +++ b/urpm/util.pm @@ -16,6 +16,7 @@ our @EXPORT = qw(min max quotespace unquotespace difference2 intersection member file_size cat_ cat_utf8 wc_l output_safe append_to_file dirname basename + file2absolute_file ); (our $VERSION) = q($Revision$) =~ /(\d+)/; @@ -31,6 +32,16 @@ sub remove_internal_name { my $x = $_[0] || ''; $x =~ s/\(\S+\)$/$1/g; $x } sub dirname { local $_ = shift; s|[^/]*/*\s*$||; s|(.)/*$|$1|; $_ || '.' } sub basename { local $_ = shift; s|/*\s*$||; s|.*/||; $_ } +sub file2absolute_file { + my ($f) = @_; + + if ($f !~ m!^/!) { + require File::Spec; + $f = File::Spec->rel2abs($f); + } + $f; +} + #- reduce pathname by removing /.. each time it appears (or . too). sub reduce_pathname { my ($url) = @_; -- cgit v1.2.1