nix-push: Add ‘--link’ flag

If ‘--link’ is given, nix-push will create hard links to the NAR files
in the store, rather than copying them.  This is faster and requires
less disk space.  However, it doesn't work if the store is on a
different file system.
This commit is contained in:
Eelco Dolstra 2012-10-17 17:01:23 -04:00
parent 167e36a5c3
commit c8daeba303
1 changed files with 8 additions and 1 deletions

View File

@ -23,6 +23,7 @@ my $force = 0;
my $destDir;
my $writeManifest = 0;
my $archivesURL;
my $link = 0;
my @roots;
for (my $n = 0; $n < scalar @ARGV; $n++) {
@ -45,6 +46,8 @@ for (my $n = 0; $n < scalar @ARGV; $n++) {
$n++;
die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
$archivesURL = $ARGV[$n];
} elsif ($arg eq "--link") {
$link = 1;
} elsif (substr($arg, 0, 1) eq "-") {
die "$0: unknown flag `$arg'\n";
} else {
@ -209,7 +212,11 @@ for (my $n = 0; $n < scalar @storePaths2; $n++) {
my $dst = "$destDir/$narName";
if (! -f $dst) {
my $tmp = "$destDir/.tmp.$$.$narName";
copy($narFile, $tmp) or die "cannot copy $narFile to $tmp: $!\n";
if ($link) {
link($narFile, $tmp) or die "cannot link $tmp to $narFile: $!\n";
} else {
copy($narFile, $tmp) or die "cannot copy $narFile to $tmp: $!\n";
}
rename($tmp, $dst) or die "cannot rename $tmp to $dst: $!\n";
}