Skip to content

Commit

Permalink
git-svn: avoid filling up the disk with temp files.
Browse files Browse the repository at this point in the history
Commit ffe256f ("git-svn: Speed up fetch")
introduced changes that create a temporary file for each object fetched by
svn.  These files should be deleted automatically, but perl apparently
doesn't do this until the process exits (or perhaps when its garbage
collector runs).

This means that on a large fetch, especially with lots of branches, we
sometimes fill up /tmp completely, which prevents the next temp file from
being written completely.  This is aggravated by the fact that a new temp
file is created for each updated file, even if that update produces a file
identical to one already in git.  Thus, it can happen even if there's lots
of disk space to store the finished repository.

We weren't adequately checking for write errors, so this would result in an
invalid file getting committed, which caused git-svn to fail later with an
invalid checksum.

This patch adds a check to syswrite() so similar problems don't lead to
corruption in the future.  It also unlink()'s each temp file explicitly
when we're done with it, so the disk doesn't need to fill up.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
Tested-by: Björn Steinbrink <B.Steinbrink@gmx.de>
Acked-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Avery Pennarun authored and Junio C Hamano committed Jun 29, 2008
1 parent 5b8a94b commit 29c70e0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion git-svn.perl
Original file line number Diff line number Diff line change
Expand Up @@ -3243,14 +3243,17 @@ sub close_file {
my ($tmp_fh, $tmp_filename) = File::Temp::tempfile(UNLINK => 1);
my $result;
while ($result = sysread($fh, my $string, 1024)) {
syswrite($tmp_fh, $string, $result);
my $wrote = syswrite($tmp_fh, $string, $result);
defined($wrote) && $wrote == $result
or croak("write $tmp_filename: $!\n");
}
defined $result or croak $!;
close $tmp_fh or croak $!;

close $fh or croak $!;

$hash = $::_repository->hash_and_insert_object($tmp_filename);
unlink($tmp_filename);
$hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
close $fb->{base} or croak $!;
} else {
Expand Down

0 comments on commit 29c70e0

Please sign in to comment.