From: Joey Hess Date: Sat, 2 Feb 2008 22:18:59 +0000 (-0500) Subject: * vidir: Applied patch from Stefan Fritsch (one part of #412176): X-Git-Tag: 0.28~2 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc053c5868a14bd166160ffd2b143dd47622aba5;p=moreutils * vidir: Applied patch from Stefan Fritsch (one part of #412176): - Check for control characters (especially newlines) in filenames and error out, since this can greatly confuse the editor or vidir. - If the source of a rename does not exist (and thus the rename will fail anyway), vidir should not move an existing target file to a tmpfile. - If a directory is renamed, vidir should take that into account when renaming files in this directory. - If a directory name is passed as name/ to vidir, vidir should not add second slash after the name. * vidir: Add support for unlinking directories. To recursivly delete a directory and its contents, pipe find to vidir, and delete the directory and its contents in the editor. Closes: #412176 --- diff --git a/debian/changelog b/debian/changelog index dad1072..ef136b2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,18 @@ moreutils (0.28) UNRELEASED; urgency=low * Moved to a git repository. + * vidir: Applied patch from Stefan Fritsch (one part of #412176): + - Check for control characters (especially newlines) in filenames + and error out, since this can greatly confuse the editor or vidir. + - If the source of a rename does not exist (and thus the rename will fail + anyway), vidir should not move an existing target file to a tmpfile. + - If a directory is renamed, vidir should take that into account when + renaming files in this directory. + - If a directory name is passed as name/ to vidir, vidir should not + add second slash after the name. + * vidir: Add support for unlinking directories. To recursivly delete + a directory and its contents, pipe find to vidir, and delete the directory + and its contents in the editor. Closes: #412176 -- Joey Hess Sat, 02 Feb 2008 17:02:35 -0500 diff --git a/vidir b/vidir index 3798da7..bf674f4 100755 --- a/vidir +++ b/vidir @@ -82,15 +82,20 @@ foreach my $item (@ARGV) { open(STDIN, "/dev/tty") || die "reopen: $!\n"; } elsif (-d $item) { + $item =~ s{/?$}{/}; opendir(DIR, $item) || die "$0: cannot read $item: $!\n"; - push @dir, map { "$item/$_" } sort readdir(DIR); + push @dir, map { "$item$_" } sort readdir(DIR); closedir DIR; } else { push @dir, $item; } } - + +if (grep(/[[:cntrl:]]/, @dir)) { + die "$0: control characters in filenames are not supported\n"; +} + my $tmp=File::Temp->new(TEMPLATE => "dirXXXXX", DIR => File::Spec->tmpdir); open (OUT, ">".$tmp->filename) || die "$0: cannot create ".$tmp->filename.": $!\n"; @@ -132,6 +137,12 @@ while () { next unless length $name; my $src=$item{$num}; + if (! (-e $src || -l $src) ) { + print STDERR "$0: $src does not exist\n"; + delete $item{$num}; + next; + } + # deal with swaps if (-e $name || -l $name) { my $tmp=$name."~"; @@ -158,8 +169,15 @@ while () { print STDERR "$0: failed to rename $src to $name: $!\n"; $error=1; } - elsif ($verbose) { - print "'$src' -> '$name'\n"; + else { + if (-d $name) { + foreach (values %item) { + s/^\Q$src\E/$name/; + } + } + if ($verbose) { + print "'$src' => '$name'\n"; + } } } delete $item{$num}; @@ -174,8 +192,19 @@ while () { close IN || die "$0: cannot read ".$tmp->filename.": $!\n"; unlink($tmp.'~') if -e $tmp.'~'; -foreach my $item (sort values %item) { - if (! unlink($item)) { +sub rm { + my $file = shift; + + if (-d $file && ! -l $file) { + return rmdir $file; + } + else { + return unlink $file; + } +} + +foreach my $item (reverse sort values %item) { + if (! rm($item)) { print STDERR "$0: failed to remove $item: $!\n"; $error=1; }