From cc6eafb3d0a53c8bb02746411d3d41403ce9eb83 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 8 Apr 2003 14:05:15 +0000 Subject: [PATCH] * FreeBSD / gcc 2.95 compatibility fixes. * A script to generate prebuilt registration scripts. --- scripts/nix-generate-regscript | 20 ++++++++++++++++ src/fix.cc | 42 ++++++++++++++++++++++------------ src/nix-regprebuilts | 17 -------------- src/nix.cc | 7 +++--- 4 files changed, 50 insertions(+), 36 deletions(-) create mode 100755 scripts/nix-generate-regscript delete mode 100755 src/nix-regprebuilts diff --git a/scripts/nix-generate-regscript b/scripts/nix-generate-regscript new file mode 100755 index 000000000..bf370f8d7 --- /dev/null +++ b/scripts/nix-generate-regscript @@ -0,0 +1,20 @@ +#! /usr/bin/perl -w + +my $dir = shift @ARGV; +$dir || die "missing directory"; +my $url = shift @ARGV; +$url || die "missing base url"; + +chdir $dir || die "cannot chdir to $dir"; + +foreach my $prebuilt (glob("*.tar.bz2")) { + + $prebuilt =~ /-([a-z0-9]+)-([a-z0-9]+).tar.bz2$/ + || die "invalid file name: $prebuilt"; + + my $pkgHash = $1; + my $prebuiltHash = $2; + + print "regprebuilt $pkgHash $prebuiltHash\n"; + print "regurl $prebuiltHash $url/$prebuilt\n"; +} diff --git a/src/fix.cc b/src/fix.cc index cb1990928..bf335bc36 100644 --- a/src/fix.cc +++ b/src/fix.cc @@ -1,6 +1,9 @@ #include #include +#include +#include + extern "C" { #include } @@ -23,13 +26,31 @@ void registerFile(string filename) } +/* Return the directory part of the given path, i.e., everything + before the final `/'. */ +string dirOf(string s) +{ + unsigned int pos = s.rfind('/'); + if (pos == string::npos) throw Error("invalid file name"); + return string(s, 0, pos); +} + + +/* Return the base name of the given path, i.e., everything following + the final `/'. */ +string baseNameOf(string s) +{ + unsigned int pos = s.rfind('/'); + if (pos == string::npos) throw Error("invalid file name"); + return string(s, pos + 1); +} + + /* Download object referenced by the given URL into the sources directory. Return the file name it was downloaded to. */ string fetchURL(string url) { - unsigned int pos = url.rfind('/'); - if (pos == string::npos) throw Error("invalid url"); - string filename(url, pos + 1); + string filename = baseNameOf(url); string fullname = nixSourcesDir + "/" + filename; /* !!! quoting */ string shellCmd = @@ -41,16 +62,6 @@ string fetchURL(string url) } -/* Return the directory part of the given path, i.e., everything - before the final `/'. */ -string dirOf(string s) -{ - unsigned int pos = s.rfind('/'); - if (pos == string::npos) throw Error("invalid file name"); - return string(s, 0, pos); -} - - /* Term evaluation functions. */ string evaluateStr(ATerm e) @@ -88,12 +99,13 @@ string evaluateFile(ATerm e, string dir) int res = system(cmd.c_str()); if (WEXITSTATUS(res) != 0) throw Error("cannot copy " + filename); + registerFile(nixSourcesDir + "/" + baseNameOf(filename)); return hashFile(filename); } else throw Error("invalid hash expression"); } -ATerm evaluatePkg(ATerm e, DescriptorMap & done) +string evaluatePkg(ATerm e, DescriptorMap & done) { char * s; if (ATmatch(e, "", &s)) { @@ -113,7 +125,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)); + return ATmake("Pkg()", evaluatePkg(t, done).c_str()); else throw Error("invalid expression type"); } diff --git a/src/nix-regprebuilts b/src/nix-regprebuilts deleted file mode 100755 index 6c9c981ee..000000000 --- a/src/nix-regprebuilts +++ /dev/null @@ -1,17 +0,0 @@ -#! /usr/bin/perl -w - -my $dir = $ARGV[0]; - -foreach my $prebuilt (glob("$dir/*.tar.bz2")) { - - $prebuilt =~ /-([a-z0-9]+)-([a-z0-9]+).tar.bz2$/ - || die "invalid file name: $prebuilt"; - - my $pkgHash = $1; - my $prebuiltHash = $2; - - print "$pkgHash -> $prebuiltHash\n"; - - system "nix regprebuilt $pkgHash $prebuiltHash"; - system "nix regfile $prebuilt"; -} diff --git a/src/nix.cc b/src/nix.cc index 9e42917a4..9364baf6c 100644 --- a/src/nix.cc +++ b/src/nix.cc @@ -6,11 +6,12 @@ #include #include +#include #include #include #include -#include +#include extern "C" { #include @@ -48,9 +49,7 @@ public: auto_ptr openDB(const string & dbname, bool readonly) { - auto_ptr db; - - db = auto_ptr(new Db2(0, 0)); + auto_ptr db(new Db2(0, 0)); db->open((nixHomeDir + "/var/nix/pkginfo.db").c_str(), dbname.c_str(), DB_HASH, readonly ? DB_RDONLY : DB_CREATE, 0666);