summaryrefslogtreecommitdiff
path: root/lorry.tar-importer
diff options
context:
space:
mode:
authorBen Brown <ben@demerara.io>2021-11-17 18:42:14 +0000
committerBen Brown <ben@demerara.io>2021-11-24 17:09:18 +0000
commitbe3c129d5f668e7cc72b3a4e0a5d164f4a32b9f0 (patch)
treeb60fba728bb48c1b5fab99fa88582573ce457489 /lorry.tar-importer
parent796a2ae9622a37ab02195880c19d2055bb2412dc (diff)
downloadlorry-be3c129d5f668e7cc72b3a4e0a5d164f4a32b9f0.tar.gz
lorry.tar-importer: support hard links
Integrates support for hard links from the change made in upstream git back in 2016. Below is the body of the upstream commit (04e0869876f726d5af9ac901911781d440e6aed2): Previously, we simply treated hard links as if they were plain files with size 0, ignoring the link type "1" and hence the link target. What we should do instead, of course, is to use the link target to get at the import mark for the contents, even if we cannot recreate the hard link per se, as Git has no concept of hard links.
Diffstat (limited to 'lorry.tar-importer')
-rwxr-xr-xlorry.tar-importer32
1 files changed, 20 insertions, 12 deletions
diff --git a/lorry.tar-importer b/lorry.tar-importer
index 10696bf..7ffdfa9 100755
--- a/lorry.tar-importer
+++ b/lorry.tar-importer
@@ -112,11 +112,7 @@ foreach my $tar_file (@ARGV)
$mtime = oct $mtime;
next if $typeflag == 5; # directory
- if ($typeflag == 2) { # symbolic link
- print FI "blob\n", "mark :$next_mark\n";
- print FI "data ", length($linkname), "\n", $linkname;
- $mode = 0120000;
- } elsif ($typeflag eq 'x') { # extended header
+ if ($typeflag eq 'x') { # extended header
# If extended header, check for path
my $pax_header = '';
while ($size > 0 && read(I, $_, 512) == 512) {
@@ -136,15 +132,21 @@ foreach my $tar_file (@ARGV)
} elsif ($name =~ m{/\z}) {
# If it's a folder, ignore
next;
- } else {
+ } elsif ($typeflag != 1) { # handle hard links later
print FI "blob\n", "mark :$next_mark\n";
- print FI "data $size\n";
- while ($size > 0 && read(I, $_, 512) == 512) {
- print FI substr($_, 0, $size);
- $size -= 512;
+ if ($typeflag == 2) { # symbolic link
+ print FI "data ", length($linkname), "\n",
+ $linkname;
+ $mode = 0120000;
+ } else {
+ print FI "data $size\n";
+ while ($size > 0 && read(I, $_, 512) == 512) {
+ print FI substr($_, 0, $size);
+ $size -= 512;
+ }
}
+ print FI "\n";
}
- print FI "\n";
next if ($typeflag eq 'g'); # ignore global header
@@ -154,7 +156,13 @@ foreach my $tar_file (@ARGV)
} else {
$path = "$name";
}
- $files{$path} = [$next_mark++, $mode];
+
+ if ($typeflag == 1) { # hard link
+ $linkname = "$prefix/$linkname" if $prefix;
+ $files{$path} = [ $files{$linkname}->[0], $mode ];
+ } else {
+ $files{$path} = [$next_mark++, $mode];
+ }
$author_time = $mtime if $mtime > $author_time;
$path =~ m,^([^/]+)/,;