diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2007-02-21 14:31:42 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2007-02-21 14:31:42 +0000 |
commit | 46e0919ced4646004cc0701b188d0a68e24e8924 (patch) | |
tree | 3262f8068c38489029753c528a123b2c685aea68 /src/libutil | |
parent | 6c9fdb17fbda181fc09a9ce1f49662ef522d006b (diff) | |
download | guix-46e0919ced4646004cc0701b188d0a68e24e8924.tar.gz |
* `nix-store --export --sign': sign the Nix archive using the RSA key
in /nix/etc/nix/signing-key.sec
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/hash.cc | 39 | ||||
-rw-r--r-- | src/libutil/hash.hh | 19 | ||||
-rw-r--r-- | src/libutil/util.cc | 15 | ||||
-rw-r--r-- | src/libutil/util.hh | 3 |
4 files changed, 56 insertions, 20 deletions
diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc index 262dbef20d..3d20d2d50d 100644 --- a/src/libutil/hash.cc +++ b/src/libutil/hash.cc @@ -282,30 +282,39 @@ Hash hashFile(HashType ht, const Path & path) } -struct HashSink : Sink +HashSink::HashSink(HashType ht) : ht(ht) { - HashType ht; - Ctx ctx; - virtual void operator () - (const unsigned char * data, unsigned int len) - { - update(ht, ctx, data, len); - } -}; + ctx = new Ctx; + start(ht, *ctx); +} + +HashSink::~HashSink() +{ + delete ctx; +} +void HashSink::operator () + (const unsigned char * data, unsigned int len) +{ + update(ht, *ctx, data, len); +} -Hash hashPath(HashType ht, const Path & path, PathFilter & filter) +Hash HashSink::finish() { - HashSink sink; - sink.ht = ht; Hash hash(ht); - start(ht, sink.ctx); - dumpPath(path, sink, filter); - finish(ht, sink.ctx, hash.hash); + nix::finish(ht, *ctx, hash.hash); return hash; } +Hash hashPath(HashType ht, const Path & path, PathFilter & filter) +{ + HashSink sink(ht); + dumpPath(path, sink, filter); + return sink.finish(); +} + + Hash compressHash(const Hash & hash, unsigned int newSize) { Hash h; diff --git a/src/libutil/hash.hh b/src/libutil/hash.hh index 78227fb6a3..85eb3c1b4d 100644 --- a/src/libutil/hash.hh +++ b/src/libutil/hash.hh @@ -2,6 +2,7 @@ #define __HASH_H #include "types.hh" +#include "serialise.hh" namespace nix { @@ -81,7 +82,23 @@ Hash compressHash(const Hash & hash, unsigned int newSize); /* Parse a string representing a hash type. */ HashType parseHashType(const string & s); - + +typedef union Ctx; + +class HashSink : public Sink +{ +private: + HashType ht; + Ctx * ctx; + +public: + HashSink(HashType ht); + ~HashSink(); + virtual void operator () (const unsigned char * data, unsigned int len); + Hash finish(); +}; + + } diff --git a/src/libutil/util.cc b/src/libutil/util.cc index fb6411408d..7671c7c7e4 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -761,7 +761,7 @@ void killUser(uid_t uid) ////////////////////////////////////////////////////////////////////// -string runProgram(Path program) +string runProgram(Path program, bool searchPath, const Strings & args) { /* Create a pipe. */ Pipe pipe; @@ -781,8 +781,17 @@ string runProgram(Path program) if (dup2(pipe.writeSide, STDOUT_FILENO) == -1) throw SysError("dupping from-hook write side"); - - execl(program.c_str(), program.c_str(), (char *) 0); + + std::vector<const char *> cargs; /* careful with c_str()! */ + cargs.push_back(program.c_str()); + for (Strings::const_iterator i = args.begin(); i != args.end(); ++i) + cargs.push_back(i->c_str()); + cargs.push_back(0); + + if (searchPath) + execvp(program.c_str(), (char * *) &cargs[0]); + else + execv(program.c_str(), (char * *) &cargs[0]); throw SysError(format("executing `%1%'") % program); } catch (std::exception & e) { diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 1cc97145c1..0ebf6f5a5f 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -231,7 +231,8 @@ void killUser(uid_t uid); /* Run a program and return its stdout in a string (i.e., like the shell backtick operator). */ -string runProgram(Path program); +string runProgram(Path program, bool searchPath = false, + const Strings & args = Strings()); /* Wrapper around _exit() on Unix and ExitProcess() on Windows. (On Cygwin, _exit() doesn't seem to do the right thing.) */ |