From 067be74ea0e105a6be785779edc7b275977e9d60 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Mon, 21 May 2007 16:55:47 +0000 Subject: - urpmi.addmedia o don't overwrite existing urpmi.cfg with an empty file when disk is full (#30945) --- NEWS | 3 +++ urpm/cfg.pm | 14 ++++++++------ urpm/util.pm | 14 +++++++++++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 9bc801b5..8ece8442 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +- urpmi.addmedia + o don't overwrite existing urpmi.cfg with an empty file + when disk is full (#30945) - urpmi o fix "Argument list too long" when calling curl/wget/proz (things should work even in case of one big transaction) (#30848) diff --git a/urpm/cfg.pm b/urpm/cfg.pm index 47761fec..23eab196 100644 --- a/urpm/cfg.pm +++ b/urpm/cfg.pm @@ -222,11 +222,7 @@ sub dump_config_raw { substitute_back($m->{$field}, $prev_block && $prev_block->{$field}); }; - open my $f, '>', $file or do { - $err = N("unable to write config file [%s]", $file); - return 0; - }; - + my @lines; foreach my $m (@$blocks) { my @l = map { if (/^(update|ignore|synthesis|noreconfigure|static|virtual)$/) { @@ -241,8 +237,14 @@ sub dump_config_raw { my $name_url = $m->{name} ? join(' ', map { quotespace($_) } $m->{name}, $substitute_back->($m, 'url')) . ' ' : ''; - print $f $name_url . "{\n", (map { " $_\n" } @l), "}\n\n"; + push @lines, join("\n", $name_url . '{', (map { " $_" } @l), "}\n"); } + + output_safe($file, join("\n", @lines)) or do { + $err = N("unable to write config file [%s]", $file); + return 0; + }; + 1; } diff --git a/urpm/util.pm b/urpm/util.pm index e6e91dca..47a89f08 100644 --- a/urpm/util.pm +++ b/urpm/util.pm @@ -12,7 +12,7 @@ our @EXPORT = qw(quotespace unquotespace copy_and_own same_size_and_mtime partition uniq - difference2 member file_size cat_ cat_utf8 dirname basename + difference2 member file_size cat_ cat_utf8 output_safe dirname basename ); (our $VERSION) = q($Revision$) =~ /(\d+)/; @@ -131,6 +131,18 @@ 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 output_safe { + my ($file, $content) = @_; + + open(my $f, '>', "$file.new") or return; + print $f $content or return; + close $f or return; + + warn "$file\n"; + rename("$file.new", $file) or return; + 1; +} + 1; __END__ -- cgit v1.2.1