From f56b7312b273546871a1eca7d34c60474d3c4050 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Apr 2003 15:36:54 +0000 Subject: * Descriptor importing in Fix. --- src/fix.cc | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'src/fix.cc') diff --git a/src/fix.cc b/src/fix.cc index bf335bc365b6..8d5cc6bf8e0b 100644 --- a/src/fix.cc +++ b/src/fix.cc @@ -2,6 +2,7 @@ #include #include +#include #include extern "C" { @@ -15,9 +16,17 @@ static string nixDescriptorDir; static string nixSourcesDir; +/* Mapping of Fix file names to the hashes of the resulting Nix + descriptors. */ typedef map DescriptorMap; +/* Forward declarations. */ + +string instantiateDescriptor(string filename, + DescriptorMap & done); + + void registerFile(string filename) { int res = system(("nix regfile " + filename).c_str()); @@ -52,12 +61,15 @@ string fetchURL(string url) { string filename = baseNameOf(url); string fullname = nixSourcesDir + "/" + filename; - /* !!! quoting */ - string shellCmd = - "cd " + nixSourcesDir + " && wget --quiet -N \"" + url + "\""; - int res = system(shellCmd.c_str()); - if (WEXITSTATUS(res) != 0) - throw Error("cannot fetch " + url); + struct stat st; + if (stat(fullname.c_str(), &st)) { + /* !!! quoting */ + string shellCmd = + "cd " + nixSourcesDir + " && wget --quiet -N \"" + url + "\""; + int res = system(shellCmd.c_str()); + if (WEXITSTATUS(res) != 0) + throw Error("cannot fetch " + url); + } return fullname; } @@ -101,17 +113,21 @@ string evaluateFile(ATerm e, string dir) throw Error("cannot copy " + filename); registerFile(nixSourcesDir + "/" + baseNameOf(filename)); return hashFile(filename); - } else throw Error("invalid hash expression"); + } else throw Error("invalid file expression"); } -string evaluatePkg(ATerm e, DescriptorMap & done) +string evaluatePkg(ATerm e, string dir, DescriptorMap & done) { char * s; + ATerm t; if (ATmatch(e, "", &s)) { checkHash(s); return s; - } else throw Error("invalid hash expression"); + } else if (ATmatch(e, "Fix()", &t)) { + string filename = absPath(evaluateStr(t), dir); /* !!! */ + return instantiateDescriptor(filename, done); + } else throw Error("invalid pkg expression"); } @@ -125,7 +141,7 @@ ATerm evaluate(ATerm e, string dir, DescriptorMap & done) else if (ATmatch(e, "File()", &t)) return ATmake("File()", evaluateFile(t, dir).c_str()); else if (ATmatch(e, "Pkg()", &t)) - return ATmake("Pkg()", evaluatePkg(t, done).c_str()); + return ATmake("Pkg()", evaluatePkg(t, dir, done).c_str()); else throw Error("invalid expression type"); } @@ -215,8 +231,8 @@ string instantiateDescriptor(string filename, /* Register it with Nix. */ registerFile(outFilename); - done[filename] = outFilename; - return outFilename; + done[filename] = outHash; + return outHash; } -- cgit 1.4.1