avoid temporary filenames with more than 255 characters.

This commit is contained in:
hjp 2010-05-26 20:09:05 +00:00
parent fe23839aaf
commit 259d97bc99
1 changed files with 9 additions and 3 deletions

View File

@ -606,10 +606,16 @@ sub linkdup {
$st->gid == $self->name2gid($f->{g}) &&
($st->mode & 07777) == $self->acl2mode($f)
) {
rename($backup_filename, "$backup_filename.$$.simba_backup") or die "cannot save $backup_filename to $backup_filename.$$.simba_backup: $!";
my ($dirname, $basename) = $backup_filename =~ m{(.*)/(.*)};
my $tmpname = "$basename.$$.simba_backup";
if (length($tmpname) > 255) {
$tmpname = substr($basename, 0, 235) . ".$$.simba_backup";
}
$tmpname = "$dirname/$tmpname";
rename($backup_filename, "$tmpname") or die "cannot save $backup_filename to $tmpname: $!";
if (link($oldfile, $backup_filename)) {
$self->log(10, "linked (dup)");
unlink("$backup_filename.$$.simba_backup") or die "cannot unlink $backup_filename.$$.simba_backup: $!";
unlink("$tmpname") or die "cannot unlink $tmpname: $!";
$sth->finish();
my $t1 = gettimeofday();
$self->{counts}{dup2}++;
@ -617,7 +623,7 @@ sub linkdup {
return $oldfile;
} else {
$self->log(5, "cannot link $oldfile to $backup_filename");
rename("$backup_filename.$$.simba_backup", $backup_filename) or die "cannot restore $backup_filename from $backup_filename.$$.simba_backup: $!";
rename("$tmpname", $backup_filename) or die "cannot restore $backup_filename from $tmpname: $!";
}
}
}