forked from lix-project/lix
* Fix the garbage collector.
This commit is contained in:
parent
7a02d95418
commit
40d9eb14df
|
@ -17,9 +17,24 @@ foreach my $arg (@ARGV) {
|
||||||
else { die "unknown argument `$arg'" };
|
else { die "unknown argument `$arg'" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opendir(DIR, $linkdir) or die "cannot open directory $linkdir: $!";
|
||||||
|
my @links = readdir DIR or die "cannot read directory $linkdir: $!";
|
||||||
|
closedir DIR;
|
||||||
|
|
||||||
|
my @roots;
|
||||||
|
foreach my $link (@links) {
|
||||||
|
$link = $linkdir . "/" . $link;
|
||||||
|
next if (!($link =~ /.id$/));
|
||||||
|
open ROOT, "<$link" or die "cannot open $link: $!";
|
||||||
|
my $root = <ROOT>;
|
||||||
|
chomp $root;
|
||||||
|
close ROOT;
|
||||||
|
push @roots, $root;
|
||||||
|
}
|
||||||
|
|
||||||
my $extraarg = "";
|
my $extraarg = "";
|
||||||
if ($keepsuccessors) { $extraarg = "--include-successors"; };
|
if ($keepsuccessors) { $extraarg = "--include-successors"; };
|
||||||
my $pid = open2(\*READ, \*WRITE, "nix --query --requisites $extraarg \$(cat $linkdir/*.id)")
|
my $pid = open2(\*READ, \*WRITE, "nix-store --query --requisites $extraarg @roots")
|
||||||
or die "determining live paths";
|
or die "determining live paths";
|
||||||
close WRITE;
|
close WRITE;
|
||||||
while (<READ>) {
|
while (<READ>) {
|
||||||
|
@ -34,8 +49,8 @@ $? == 0 or die "determining live paths";
|
||||||
|
|
||||||
exit 0 if ($invert);
|
exit 0 if ($invert);
|
||||||
|
|
||||||
opendir(DIR, $storedir) or die "cannot opendir $storedir: $!";
|
opendir(DIR, $storedir) or die "cannot open directory $storedir: $!";
|
||||||
my @names = readdir(DIR);
|
my @names = readdir DIR;
|
||||||
closedir DIR;
|
closedir DIR;
|
||||||
|
|
||||||
foreach my $name (@names) {
|
foreach my $name (@names) {
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "store.hh"
|
#include "store.hh"
|
||||||
|
@ -307,11 +304,7 @@ void addTextToStore(const Path & dstPath, const string & s)
|
||||||
PathLocks outputLock(lockPaths);
|
PathLocks outputLock(lockPaths);
|
||||||
|
|
||||||
if (!isValidPath(dstPath)) {
|
if (!isValidPath(dstPath)) {
|
||||||
|
writeStringToFile(dstPath, s);
|
||||||
AutoCloseFD fd = open(dstPath.c_str(), O_CREAT | O_EXCL | O_WRONLY, 0666);
|
|
||||||
if (fd == -1) throw SysError(format("creating store file `%1%'") % dstPath);
|
|
||||||
|
|
||||||
writeFull(fd, (unsigned char *) s.c_str(), s.size());
|
|
||||||
|
|
||||||
Transaction txn(nixDB);
|
Transaction txn(nixDB);
|
||||||
registerValidPath(txn, dstPath);
|
registerValidPath(txn, dstPath);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
|
|
||||||
|
@ -192,6 +193,16 @@ Path createTempDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void writeStringToFile(const Path & path, const string & s)
|
||||||
|
{
|
||||||
|
AutoCloseFD fd = open(path.c_str(),
|
||||||
|
O_CREAT | O_EXCL | O_WRONLY, 0666);
|
||||||
|
if (fd == -1)
|
||||||
|
throw SysError(format("creating file `%1%'") % path);
|
||||||
|
writeFull(fd, (unsigned char *) s.c_str(), s.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Verbosity verbosity = lvlError;
|
Verbosity verbosity = lvlError;
|
||||||
|
|
||||||
static int nestingLevel = 0;
|
static int nestingLevel = 0;
|
||||||
|
|
|
@ -87,6 +87,11 @@ void makePathReadOnly(const Path & path);
|
||||||
/* Create a temporary directory. */
|
/* Create a temporary directory. */
|
||||||
Path createTempDir();
|
Path createTempDir();
|
||||||
|
|
||||||
|
/* Create a file and write the given text to it. The file is written
|
||||||
|
in binary mode (i.e., no end-of-line conversions). The path should
|
||||||
|
not already exist. */
|
||||||
|
void writeStringToFile(const Path & path, const string & s);
|
||||||
|
|
||||||
|
|
||||||
/* Messages. */
|
/* Messages. */
|
||||||
|
|
||||||
|
|
|
@ -139,6 +139,8 @@ Path createLink(Path outPath, Path drvPath)
|
||||||
num++;
|
num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writeStringToFile(linkPath + "-src.id", drvPath);
|
||||||
|
|
||||||
return linkPath;
|
return linkPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue