summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2008-07-03 16:38:18 +0000
committerPascal Rigaux <pixel@mandriva.com>2008-07-03 16:38:18 +0000
commitb0ba6bfa5a2a72a71c175e5a32660fee6668722e (patch)
tree928d7d37399d8cf53dff28c88c74d814a448bb05
parentd65770eee171b53272716aa5952ad9fd34b314d3 (diff)
downloadurpmi-b0ba6bfa5a2a72a71c175e5a32660fee6668722e.tar
urpmi-b0ba6bfa5a2a72a71c175e5a32660fee6668722e.tar.gz
urpmi-b0ba6bfa5a2a72a71c175e5a32660fee6668722e.tar.bz2
urpmi-b0ba6bfa5a2a72a71c175e5a32660fee6668722e.tar.xz
urpmi-b0ba6bfa5a2a72a71c175e5a32660fee6668722e.zip
- add wc_l()
- allow to give a backup extension to output_safe()
-rw-r--r--urpm/util.pm7
1 files changed, 5 insertions, 2 deletions
diff --git a/urpm/util.pm b/urpm/util.pm
index 0a7bbd00..09b20467 100644
--- a/urpm/util.pm
+++ b/urpm/util.pm
@@ -14,7 +14,8 @@ our @EXPORT = qw(min max quotespace unquotespace
partition put_in_hash uniq uniq_
begins_with
difference2 intersection member
- file_size cat_ cat_utf8 output_safe append_to_file dirname basename
+ file_size cat_ cat_utf8 wc_l
+ output_safe append_to_file dirname basename
);
(our $VERSION) = q($Revision$) =~ /(\d+)/;
@@ -142,6 +143,7 @@ sub intersection { my (%l, @m); @l{@{shift @_}} = (); foreach (@_) { @m = grep {
sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 }
sub cat_ { my @l = map { my $F; open($F, '<', $_) ? <$F> : () } @_; wantarray() ? @l : join '', @l }
sub cat_utf8 { my @l = map { my $F; open($F, '<:utf8', $_) ? <$F> : () } @_; wantarray() ? @l : join '', @l }
+sub wc_l { my $F; open($F, '<', $_[0]) or return; my $count = 0; while (<$F>) { $count++ } $count }
sub uniq_(&@) {
my $f = shift;
@@ -151,12 +153,13 @@ sub uniq_(&@) {
}
sub output_safe {
- my ($file, $content) = @_;
+ my ($file, $content, $o_backup_ext) = @_;
open(my $f, '>', "$file.new") or return;
print $f $content or return;
close $f or return;
+ rename($file, "$file$o_backup_ext") or return if $o_backup_ext;
rename("$file.new", $file) or return;
1;
}