forked from lix-project/lix
* Make the creation of user environments much faster and more storage
efficient by creating only a single symlink to entire directory trees unless a collission occurs.
This commit is contained in:
parent
bf3863b546
commit
2be8ac48bb
|
@ -2,71 +2,92 @@
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Cwd;
|
use Cwd;
|
||||||
|
use IO::Handle;
|
||||||
|
|
||||||
|
STDOUT->autoflush(1);
|
||||||
|
|
||||||
|
my $out = $ENV{"out"};
|
||||||
|
mkdir "$out", 0755 || die "error creating $out";
|
||||||
|
|
||||||
my $selfdir = $ENV{"out"};
|
|
||||||
mkdir "$selfdir", 0755 || die "error creating $selfdir";
|
|
||||||
|
|
||||||
# For each activated package, create symlinks.
|
# For each activated package, create symlinks.
|
||||||
|
|
||||||
sub createLinks {
|
sub createLinks {
|
||||||
my $srcdir = shift;
|
my $srcDir = shift;
|
||||||
my $dstdir = shift;
|
my $dstDir = shift;
|
||||||
|
|
||||||
my @srcfiles = glob("$srcdir/*");
|
my @srcFiles = glob("$srcDir/*");
|
||||||
|
|
||||||
foreach my $srcfile (@srcfiles) {
|
foreach my $srcFile (@srcFiles) {
|
||||||
my $basename = $srcfile;
|
my $baseName = $srcFile;
|
||||||
$basename =~ s/^.*\///g; # strip directory
|
$baseName =~ s/^.*\///g; # strip directory
|
||||||
my $dstfile = "$dstdir/$basename";
|
my $dstFile = "$dstDir/$baseName";
|
||||||
if ($srcfile =~ /\/propagated-build-inputs$/) {
|
|
||||||
} elsif (-d $srcfile) {
|
if ($srcFile =~ /\/propagated-build-inputs$/ ||
|
||||||
# !!! hack for resolving name clashes
|
$srcFile =~ /\/nix-support$/)
|
||||||
if (!-e $dstfile) {
|
{
|
||||||
mkdir $dstfile, 0755 ||
|
# Do noting.
|
||||||
die "error creating directory $dstfile";
|
|
||||||
}
|
}
|
||||||
-d $dstfile or die "$dstfile is not a directory";
|
|
||||||
createLinks($srcfile, $dstfile);
|
elsif (-d $srcFile) {
|
||||||
} elsif (-l $dstfile) {
|
|
||||||
my $target = readlink($dstfile);
|
lstat $dstFile;
|
||||||
die "collission between $srcfile and $target";
|
|
||||||
} else {
|
if (-d _) {
|
||||||
# print "linking $dstfile to $srcfile\n";
|
createLinks($srcFile, $dstFile);
|
||||||
symlink($srcfile, $dstfile) ||
|
}
|
||||||
die "error creating link $dstfile";
|
|
||||||
|
elsif (-l _) {
|
||||||
|
my $target = readlink $dstFile or die;
|
||||||
|
if (!-d $target) {
|
||||||
|
die "collission between directory `$srcFile' and non-directory `$target'";
|
||||||
|
}
|
||||||
|
unlink $dstFile or die "error unlinking `$dstFile': $!";
|
||||||
|
mkdir $dstFile, 0755 ||
|
||||||
|
die "error creating directory `$dstFile': $!";
|
||||||
|
createLinks($target, $dstFile);
|
||||||
|
createLinks($srcFile, $dstFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
symlink($srcFile, $dstFile) ||
|
||||||
|
die "error creating link `$dstFile': $!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
elsif (-l $dstFile) {
|
||||||
|
my $target = readlink $dstFile;
|
||||||
|
die "collission between `$srcFile' and `$target'";
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
# print "linking $dstFile to $srcFile\n";
|
||||||
|
symlink($srcFile, $dstFile) ||
|
||||||
|
die "error creating link `$dstFile': $!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
my %done;
|
my %done;
|
||||||
|
|
||||||
sub addPkg {
|
sub addPkg {
|
||||||
my $pkgdir = shift;
|
my $pkgDir = shift;
|
||||||
|
|
||||||
return if (defined $done{$pkgdir});
|
return if (defined $done{$pkgDir});
|
||||||
$done{$pkgdir} = 1;
|
$done{$pkgDir} = 1;
|
||||||
|
|
||||||
# print "merging $pkgdir\n";
|
createLinks("$pkgDir", "$out");
|
||||||
|
|
||||||
createLinks("$pkgdir", "$selfdir");
|
|
||||||
|
|
||||||
# if (-f "$pkgdir/envpkgs") {
|
|
||||||
# my $envpkgs = `cat $pkgdir/envpkgs`;
|
|
||||||
# chomp $envpkgs;
|
|
||||||
# my @envpkgs = split / +/, $envpkgs;
|
|
||||||
# foreach my $envpkg (@envpkgs) {
|
|
||||||
# addPkg($envpkg);
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
my @args = split ' ', $ENV{"derivations"};
|
my @args = split ' ', $ENV{"derivations"};
|
||||||
|
|
||||||
while (scalar @args > 0) {
|
while (scalar @args > 0) {
|
||||||
my $drvpath = shift @args;
|
my $drvPath = shift @args;
|
||||||
print "adding $drvpath\n";
|
print "adding $drvPath\n";
|
||||||
addPkg($drvpath);
|
addPkg($drvPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
symlink($ENV{"manifest"}, "$selfdir/manifest") or die "cannot create manifest";
|
|
||||||
|
|
||||||
|
symlink($ENV{"manifest"}, "$out/manifest") or die "cannot create manifest";
|
||||||
|
|
Loading…
Reference in a new issue