From 259d97bc99c22570f3d1507de69ce052a75b1989 Mon Sep 17 00:00:00 2001 From: hjp Date: Wed, 26 May 2010 20:09:05 +0000 Subject: [PATCH] avoid temporary filenames with more than 255 characters. --- lib/Simba/CA.pm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Simba/CA.pm b/lib/Simba/CA.pm index 1429cb2..1445d7c 100644 --- a/lib/Simba/CA.pm +++ b/lib/Simba/CA.pm @@ -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: $!"; } } }