#include "store-api.hh" #include "globals.hh" #include "util.hh" #include namespace nix { GCOptions::GCOptions() { action = gcDeleteDead; ignoreLiveness = false; maxFreed = ULLONG_MAX; } bool isInStore(const Path & path) { return isInDir(path, settings.nixStore); } bool isStorePath(const Path & path) { return isInStore(path) && path.find('/', settings.nixStore.size() + 1) == Path::npos; } void assertStorePath(const Path & path) { if (!isStorePath(path)) throw Error(format("path `%1%' is not in the store") % path); } Path toStorePath(const Path & path) { if (!isInStore(path)) throw Error(format("path `%1%' is not in the store") % path); Path::size_type slash = path.find('/', settings.nixStore.size() + 1); if (slash == Path::npos) return path; else return Path(path, 0, slash); } string storePathToName(const Path & path) { assertStorePath(path); return string(path, settings.nixStor
aboutsummaryrefslogtreecommitdiff
#ifndef BOOST_THROW_EXCEPTION_HPP_INCLUDED
#define BOOST_THROW_EXCEPTION_HPP_INCLUDED

// MS compatible compilers support #pragma once

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif

//
//  boost/throw_exception.hpp
//
//  Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
//
//  Permission to copy, use, modify, sell and distribute this software
//  is granted provided this copyright notice appears in all copies.
//  This software is provided "as is" without express or implied
//  warranty, and with no claim as to its suitability for any purpose.
//
//  http://www.boost.org/libs/utility/throw_exception.html
//

//#include <boost/config.hpp>

#ifdef BOOST_NO_EXCEPTIONS
# include <exception>
#endif

namespace boost
{

#ifdef BOOST_NO_EXCEPTIONS

void throw_exception(std::exception const & e); // user defined

#else

template<class E> void throw_exception(E const & e)
{
    throw e;
}

#endif

} // namespace boost

#endif // #ifndef BOOST_THROW_EXCEPTION_HPP_INCLUDED
f the path from which this store path is copied, as returned by hashPath() if = "output:out": for non-fixed derivation outputs: the derivation (see hashDerivationModulo() in primops.cc) for paths copied by addToStore() or produced by fixed-output derivations: the string "fixed:out:::", where = "r:" for recursive (path) hashes, or "" or flat (file) hashes = "md5", "sha1" or "sha256" = base-16 representation of the path or flat hash of the contents of the path (or expected contents of the path for fixed-output derivations) It would have been nicer to handle fixed-output derivations under "source", e.g. have something like "source:", but we're stuck with this for now... The main reason for this way of computing names is to prevent name collisions (for security). For instance, it shouldn't be feasible to come up with a derivation whose output path collides with the path for a copied source. The former would have a starting with "output:out:", while the latter would have a <2> starting with "source:". */ Path makeStorePath(const string & type, const Hash & hash, const string & name) { /* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */ string s = type + ":sha256:" + printHash(hash) + ":" + settings.nixStore + ":" + name; checkStoreName(name); return settings.nixStore + "/" + printHash32(compressHash(hashString(htSHA256, s), 20)) + "-" + name; } Path makeOutputPath(const string & id, const Hash & hash, const string & name) { return makeStorePath("output:" + id, hash, name + (id == "out" ? "" : "-" + id)); } Path makeFixedOutputPath(bool recursive, HashType hashAlgo, Hash hash, string name) { return hashAlgo == htSHA256 && recursive ? makeStorePath("source", hash, name) : makeStorePath("output:out", hashString(htSHA256, "fixed:out:" + (recursive ? (string) "r:" : "") + printHashType(hashAlgo) + ":" + printHash(hash) + ":"), name); } Path computeStorePathForText(const string & name, const string & s, const PathSet & references) { Hash hash = hashString(htSHA256, s); /* Stuff the references (if any) into the type. This is a bit hacky, but we can't put them in `s' since that would be ambiguous. */ string type = "text"; foreach (PathSet::const_iterator, i, references) { type += ":"; type += *i; } return makeStorePath(type, hash, name); } /* Return a string accepted by decodeValidPathInfo() that registers the specified paths as valid. Note: it's the responsibility of the caller to provide a closure. */ string StoreAPI::makeValidityRegistration(const PathSet & paths, bool showDerivers, bool showHash) { string s = ""; foreach (PathSet::iterator, i, paths) { s += *i + "\n"; ValidPathInfo info = queryPathInfo(*i); if (showHash) { s += printHash(info.hash) + "\n"; s += (format("%1%\n") % info.narSize).str(); } Path deriver = showDerivers ? info.deriver : ""; s += deriver + "\n"; s += (format("%1%\n") % info.references.size()).str(); foreach (PathSet::iterator, j, info.references) s += *j + "\n"; } return s; } string showPaths(const PathSet & paths) { string s; foreach (PathSet::const_iterator, i, paths) { if (s.size() != 0) s += ", "; s += "`" + *i + "'"; } return s; } void exportPaths(StoreAPI & store, const Paths & paths, bool sign, Sink & sink) { foreach (Paths::const_iterator, i, paths) { writeInt(1, sink); store.exportPath(*i, sign, sink); } writeInt(0, sink); } Path readStorePath(Source & from) { Path path = readString(from); assertStorePath(path); return path; } template T readStorePaths(Source & from) { T paths = readStrings(from); foreach (typename T::iterator, i, paths) assertStorePath(*i); return paths; } template PathSet readStorePaths(Source & from); } #include "local-store.hh" #include "serialise.hh" namespace nix { std::shared_ptr store; std::shared_ptr openStore(bool reserveSpace) { return std::shared_ptr(new LocalStore(reserveSpace)); } }