* Fix the garbage collector.

This commit is contained in:
Eelco Dolstra 2003-11-22 15:58:34 +00:00
parent 7a02d95418
commit 40d9eb14df
5 changed files with 38 additions and 12 deletions

View file

@ -17,9 +17,24 @@ foreach my $arg (@ARGV) {
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 = "";
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";
close WRITE;
while (<READ>) {
@ -34,8 +49,8 @@ $? == 0 or die "determining live paths";
exit 0 if ($invert);
opendir(DIR, $storedir) or die "cannot opendir $storedir: $!";
my @names = readdir(DIR);
opendir(DIR, $storedir) or die "cannot open directory $storedir: $!";
my @names = readdir DIR;
closedir DIR;
foreach my $name (@names) {

View file

@ -1,9 +1,6 @@
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include "store.hh"
@ -307,11 +304,7 @@ void addTextToStore(const Path & dstPath, const string & s)
PathLocks outputLock(lockPaths);
if (!isValidPath(dstPath)) {
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());
writeStringToFile(dstPath, s);
Transaction txn(nixDB);
registerValidPath(txn, dstPath);

View file

@ -6,6 +6,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#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;
static int nestingLevel = 0;

View file

@ -87,6 +87,11 @@ void makePathReadOnly(const Path & path);
/* Create a temporary directory. */
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. */

View file

@ -139,6 +139,8 @@ Path createLink(Path outPath, Path drvPath)
num++;
}
writeStringToFile(linkPath + "-src.id", drvPath);
return linkPath;
}
@ -290,7 +292,7 @@ void uninstallDerivations(EvalState & state, Strings drvNames)
installedDrvs.erase(j->second);
}
createUserEnv(state, installedDrvs);
createUserEnv(state, installedDrvs);
}