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 <joeyh@debian.org> Sat, 02 Feb 2008 17:02:35 -0500
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";
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."~";
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};
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;
}