about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/build.cc53
-rw-r--r--src/libstore/build.hh9
-rw-r--r--src/libstore/db.cc18
-rw-r--r--src/libstore/db.hh16
-rw-r--r--src/libstore/derivations.cc7
-rw-r--r--src/libstore/derivations.hh16
-rw-r--r--src/libstore/gc.cc13
-rw-r--r--src/libstore/gc.hh8
-rw-r--r--src/libstore/globals.cc11
-rw-r--r--src/libstore/globals.hh11
-rw-r--r--src/libstore/misc.cc9
-rw-r--r--src/libstore/misc.hh6
-rw-r--r--src/libstore/pathlocks.cc11
-rw-r--r--src/libstore/pathlocks.hh10
-rw-r--r--src/libstore/references.cc15
-rw-r--r--src/libstore/references.hh6
-rw-r--r--src/libstore/store.cc46
-rw-r--r--src/libstore/store.hh10
18 files changed, 193 insertions, 82 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index c953707a5126..647671036de1 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -1,3 +1,13 @@
+#include "build.hh"
+#include "references.hh"
+#include "pathlocks.hh"
+#include "misc.hh"
+#include "globals.hh"
+#include "gc.hh"
+#include "store.hh"
+#include "db.hh"
+#include "util.hh"
+
 #include <map>
 #include <iostream>
 #include <sstream>
@@ -15,13 +25,11 @@
 #include <pwd.h>
 #include <grp.h>
 
-#include "build.hh"
-#include "references.hh"
-#include "pathlocks.hh"
-#include "misc.hh"
-#include "globals.hh"
-#include "gc.hh"
 
+namespace nix {
+
+using std::map;
+    
 
 /* !!! TODO derivationFromPath shouldn't be used here */
 
@@ -38,8 +46,8 @@ class Worker;
 
 /* A pointer to a goal. */
 class Goal;
-typedef shared_ptr<Goal> GoalPtr;
-typedef weak_ptr<Goal> WeakGoalPtr;
+typedef boost::shared_ptr<Goal> GoalPtr;
+typedef boost::weak_ptr<Goal> WeakGoalPtr;
 
 /* Set of goals. */
 typedef set<GoalPtr> Goals;
@@ -50,7 +58,7 @@ typedef map<Path, WeakGoalPtr> WeakGoalMap;
 
 
 
-class Goal : public enable_shared_from_this<Goal>
+class Goal : public boost::enable_shared_from_this<Goal>
 {
 public:
     typedef enum {ecBusy, ecSuccess, ecFailed} ExitCode;
@@ -447,8 +455,8 @@ static void killUser(uid_t uid)
             if (kill(-1, SIGKILL) == -1)
                 throw SysError(format("cannot kill processes for UID `%1%'") % uid);
         
-        } catch (exception & e) {
-            cerr << format("build error: %1%\n") % e.what();
+        } catch (std::exception & e) {
+            std::cerr << format("build error: %1%\n") % e.what();
             quickExit(1);
         }
         quickExit(0);
@@ -930,8 +938,8 @@ DerivationGoal::HookReply DerivationGoal::tryBuildHook()
             
             throw SysError(format("executing `%1%'") % buildHook);
             
-        } catch (exception & e) {
-            cerr << format("build error: %1%\n") % e.what();
+        } catch (std::exception & e) {
+            std::cerr << format("build error: %1%\n") % e.what();
         }
         quickExit(1);
     }
@@ -1326,8 +1334,8 @@ void DerivationGoal::startBuilder()
             throw SysError(format("executing `%1%'")
                 % drv.builder);
             
-        } catch (exception & e) {
-            cerr << format("build error: %1%\n") % e.what();
+        } catch (std::exception & e) {
+            std::cerr << format("build error: %1%\n") % e.what();
         }
         quickExit(1);
     }
@@ -1593,7 +1601,7 @@ private:
     Pid pid;
 
     /* Lock on the store path. */
-    shared_ptr<PathLocks> outputLock;
+    boost::shared_ptr<PathLocks> outputLock;
     
     typedef void (SubstitutionGoal::*GoalState)();
     GoalState state;
@@ -1719,7 +1727,7 @@ void SubstitutionGoal::tryToRun()
     }
 
     /* Acquire a lock on the output path. */
-    outputLock = shared_ptr<PathLocks>(new PathLocks);
+    outputLock = boost::shared_ptr<PathLocks>(new PathLocks);
     outputLock->lockPaths(singleton<PathSet>(storePath),
         (format("waiting for lock on `%1%'") % storePath).str());
 
@@ -1767,8 +1775,8 @@ void SubstitutionGoal::tryToRun()
             
             throw SysError(format("executing `%1%'") % sub.program);
             
-        } catch (exception & e) {
-            cerr << format("substitute error: %1%\n") % e.what();
+        } catch (std::exception & e) {
+            std::cerr << format("substitute error: %1%\n") % e.what();
         }
         quickExit(1);
     }
@@ -1930,8 +1938,8 @@ static void removeGoal(GoalPtr goal, WeakGoalMap & goalMap)
 
 void Worker::removeGoal(GoalPtr goal)
 {
-    ::removeGoal(goal, derivationGoals);
-    ::removeGoal(goal, substitutionGoals);
+    nix::removeGoal(goal, derivationGoals);
+    nix::removeGoal(goal, substitutionGoals);
     if (topGoals.find(goal) != topGoals.end()) {
         topGoals.erase(goal);
         /* If a top-level goal failed, then kill all other goals
@@ -2160,3 +2168,6 @@ void ensurePath(const Path & path)
     if (goal->getExitCode() != Goal::ecSuccess)
         throw Error(format("path `%1%' does not exist and cannot be created") % path);
 }
+
+ 
+}
diff --git a/src/libstore/build.hh b/src/libstore/build.hh
index 489a6cabc8a5..c90c126769ef 100644
--- a/src/libstore/build.hh
+++ b/src/libstore/build.hh
@@ -1,8 +1,13 @@
 #ifndef __BUILD_H
 #define __BUILD_H
 
-#include "derivations.hh"
 
+#include "types.hh"
+
+
+namespace nix {
+
+    
 /* Ensure that the output paths of the derivation are valid.  If they
    are already valid, this is a no-op.  Otherwise, validity can
    be reached in two ways.  First, if the output paths have
@@ -16,5 +21,7 @@ void buildDerivations(const PathSet & drvPaths);
 void ensurePath(const Path & storePath);
 
     
+}
+
 
 #endif /* !__BUILD_H */
diff --git a/src/libstore/db.cc b/src/libstore/db.cc
index 7f428dc488e6..ca5d0582a099 100644
--- a/src/libstore/db.cc
+++ b/src/libstore/db.cc
@@ -1,3 +1,7 @@
+#include "db.hh"
+#include "util.hh"
+#include "pathlocks.hh"
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -7,9 +11,8 @@
 
 #include <db_cxx.h>
 
-#include "db.hh"
-#include "util.hh"
-#include "pathlocks.hh"
+
+namespace nix {
 
 
 /* Wrapper class to ensure proper destruction. */
@@ -112,7 +115,7 @@ Db * Database::getDb(TableId table)
     if (table == 0)
         throw Error("database table is not open "
             "(maybe you don't have sufficient permission?)");
-    map<TableId, Db *>::iterator i = tables.find(table);
+    std::map<TableId, Db *>::iterator i = tables.find(table);
     if (i == tables.end())
         throw Error("unknown table id");
     return i->second;
@@ -263,10 +266,10 @@ void Database::close()
 
     try {
 
-        for (map<TableId, Db *>::iterator i = tables.begin();
+        for (std::map<TableId, Db *>::iterator i = tables.begin();
              i != tables.end(); )
         {
-            map<TableId, Db *>::iterator j = i;
+            std::map<TableId, Db *>::iterator j = i;
             ++j;
             closeTable(i->first);
             i = j;
@@ -433,3 +436,6 @@ void Database::enumTable(const Transaction & txn, TableId table,
 
     } catch (DbException e) { rethrow(e); }
 }
+
+ 
+}
diff --git a/src/libstore/db.hh b/src/libstore/db.hh
index 0315728de597..54f490f885d5 100644
--- a/src/libstore/db.hh
+++ b/src/libstore/db.hh
@@ -1,13 +1,9 @@
 #ifndef __DB_H
 #define __DB_H
 
-#include <string>
-#include <list>
-#include <map>
-
-#include "util.hh"
+#include "types.hh"
 
-using namespace std;
+#include <map>
 
 
 /* Defined externally. */
@@ -16,6 +12,9 @@ class DbEnv;
 class Db;
 
 
+namespace nix {
+
+
 class Database;
 
 
@@ -53,7 +52,7 @@ private:
     DbEnv * env;
 
     TableId nextId;
-    map<TableId, Db *> tables;
+    std::map<TableId, Db *> tables;
 
     void requireEnv();
 
@@ -99,5 +98,8 @@ public:
     DbNoPermission(const format & f) : Error(f) { };
 };
 
+ 
+}
+
 
 #endif /* !__DB_H */
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index e2d81bda83e7..d6291cd45ac3 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -1,11 +1,13 @@
 #include "derivations.hh"
-#include "globals.hh"
 #include "store.hh"
 
 #include "derivations-ast.hh"
 #include "derivations-ast.cc"
 
 
+namespace nix {
+
+
 Hash hashTerm(ATerm t)
 {
     return hashString(htSHA256, atPrint(t));
@@ -170,3 +172,6 @@ bool isDerivation(const string & fileName)
         fileName.size() >= drvExtension.size() &&
         string(fileName, fileName.size() - drvExtension.size()) == drvExtension;
 }
+
+ 
+}
diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh
index 9358db2edae0..d1c9db50849f 100644
--- a/src/libstore/derivations.hh
+++ b/src/libstore/derivations.hh
@@ -2,7 +2,12 @@
 #define __DERIVATIONS_H
 
 #include "aterm.hh"
-#include "store.hh"
+#include "hash.hh"
+
+#include <map>
+
+
+namespace nix {
 
 
 /* Extension of derivations in the Nix store. */
@@ -27,13 +32,13 @@ struct DerivationOutput
     }
 };
 
-typedef map<string, DerivationOutput> DerivationOutputs;
+typedef std::map<string, DerivationOutput> DerivationOutputs;
 
 /* For inputs that are sub-derivations, we specify exactly which
    output IDs we are interested in. */
-typedef map<Path, StringSet> DerivationInputs;
+typedef std::map<Path, StringSet> DerivationInputs;
 
-typedef map<string, string> StringPairs;
+typedef std::map<string, string> StringPairs;
 
 struct Derivation
 {
@@ -63,5 +68,8 @@ ATerm unparseDerivation(const Derivation & drv);
    derivations. */
 bool isDerivation(const string & fileName);
 
+ 
+}
+
 
 #endif /* !__DERIVATIONS_H */
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index 37fde29ca035..59e71daa0b46 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -1,7 +1,10 @@
-#include "globals.hh"
 #include "gc.hh"
+#include "globals.hh"
 #include "misc.hh"
 #include "pathlocks.hh"
+#include "store.hh"
+#include "db.hh"
+#include "util.hh"
 
 #include <boost/shared_ptr.hpp>
 
@@ -17,6 +20,9 @@
 #endif
 
 
+namespace nix {
+
+
 static string gcLockName = "gc.lock";
 static string tempRootsDir = "temproots";
 static string gcRootsDir = "gcroots";
@@ -192,7 +198,7 @@ void removeTempRoots()
 }
 
 
-typedef shared_ptr<AutoCloseFD> FDPtr;
+typedef boost::shared_ptr<AutoCloseFD> FDPtr;
 typedef list<FDPtr> FDs;
 
 
@@ -558,3 +564,6 @@ void collectGarbage(GCAction action, const PathSet & pathsToDelete,
         }
     }
 }
+
+ 
+}
diff --git a/src/libstore/gc.hh b/src/libstore/gc.hh
index c6b13bc471ac..54fc4dec4beb 100644
--- a/src/libstore/gc.hh
+++ b/src/libstore/gc.hh
@@ -1,7 +1,10 @@
 #ifndef __GC_H
 #define __GC_H
 
-#include "util.hh"
+#include "types.hh"
+
+
+namespace nix {
 
 
 /* Garbage collector operation. */
@@ -39,4 +42,7 @@ Path addPermRoot(const Path & storePath, const Path & gcRoot,
     bool indirect);
 
 
+}
+
+
 #endif /* !__GC_H */
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index f61fe167d870..466d0e0b26d7 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -1,9 +1,13 @@
 #include "globals.hh"
+#include "util.hh"
 
 #include <map>
 #include <algorithm>
 
 
+namespace nix {
+
+
 string nixStore = "/UNINIT";
 string nixDataDir = "/UNINIT";
 string nixLogDir = "/UNINIT";
@@ -23,7 +27,7 @@ string thisSystem = "unset";
 
 static bool settingsRead = false;
 
-static map<string, Strings> settings;
+static std::map<string, Strings> settings;
 
 
 string & at(Strings & ss, unsigned int n)
@@ -72,7 +76,7 @@ static void readSettings()
 Strings querySetting(const string & name, const Strings & def)
 {
     if (!settingsRead) readSettings();
-    map<string, Strings>::iterator i = settings.find(name);
+    std::map<string, Strings>::iterator i = settings.find(name);
     return i == settings.end() ? def : i->second;
 }
 
@@ -98,3 +102,6 @@ bool queryBoolSetting(const string & name, bool def)
     else throw Error(format("configuration option `%1%' should be either `true' or `false', not `%2%'")
         % name % v);
 }
+
+ 
+}
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index 03aaa13d8917..9441dc344a73 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -1,11 +1,11 @@
 #ifndef __GLOBALS_H
 #define __GLOBALS_H
 
-#include <string>
-#include <set>
-#include "util.hh"
+#include "types.hh"
+
+
+namespace nix {
 
-using namespace std;
 
 /* Path names. */
 
@@ -67,5 +67,8 @@ string querySetting(const string & name, const string & def);
 
 bool queryBoolSetting(const string & name, bool def);
 
+    
+}
+
 
 #endif /* !__GLOBALS_H */
diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc
index 91cf25f27187..156d059b6f30 100644
--- a/src/libstore/misc.cc
+++ b/src/libstore/misc.cc
@@ -1,4 +1,10 @@
+#include "misc.hh"
+#include "store.hh"
 #include "build.hh"
+#include "db.hh"
+
+
+namespace nix {
 
 
 Derivation derivationFromPath(const Path & drvPath)
@@ -81,3 +87,6 @@ void queryMissing(const PathSet & targets,
         }
     }
 }
+
+ 
+}
diff --git a/src/libstore/misc.hh b/src/libstore/misc.hh
index f758f5bfd58e..ad1ad80eb186 100644
--- a/src/libstore/misc.hh
+++ b/src/libstore/misc.hh
@@ -4,6 +4,9 @@
 #include "derivations.hh"
 
 
+namespace nix {
+
+
 /* Read a derivation, after ensuring its existence through
    ensurePath(). */
 Derivation derivationFromPath(const Path & drvPath);
@@ -29,4 +32,7 @@ void queryMissing(const PathSet & targets,
     PathSet & willBuild, PathSet & willSubstitute);
 
 
+}
+
+
 #endif /* !__MISC_H */
diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc
index 8d0e6c3299ac..03ba4f212439 100644
--- a/src/libstore/pathlocks.cc
+++ b/src/libstore/pathlocks.cc
@@ -1,17 +1,21 @@
+#include "pathlocks.hh"
+#include "util.hh"
+
 #include <cerrno>
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 
-#include "pathlocks.hh"
-
 #ifdef __CYGWIN__
 #include <windows.h>
 #include <sys/cygwin.h>
 #endif
 
 
+namespace nix {
+
+
 int openLockFile(const Path & path, bool create)
 {
     AutoCloseFD fd;
@@ -220,3 +224,6 @@ void PathLocks::setDeletion(bool deletePaths)
 {
     this->deletePaths = deletePaths;
 }
+
+ 
+}
diff --git a/src/libstore/pathlocks.hh b/src/libstore/pathlocks.hh
index 911fe4579f28..87bb7bf3ef71 100644
--- a/src/libstore/pathlocks.hh
+++ b/src/libstore/pathlocks.hh
@@ -1,7 +1,10 @@
 #ifndef __PATHLOCKS_H
 #define __PATHLOCKS_H
 
-#include "util.hh"
+#include "types.hh"
+
+
+namespace nix {
 
 
 /* Open (possibly create) a lock file and return the file descriptor.
@@ -22,7 +25,7 @@ bool lockFile(int fd, LockType lockType, bool wait);
 class PathLocks 
 {
 private:
-    typedef pair<int, Path> FDPair;
+    typedef std::pair<int, Path> FDPair;
     list<FDPair> fds;
     bool deletePaths;
 
@@ -37,4 +40,7 @@ public:
 };
 
 
+}
+
+
 #endif /* !__PATHLOCKS_H */
diff --git a/src/libstore/references.cc b/src/libstore/references.cc
index d67e5b9dcc82..aba4ef01072f 100644
--- a/src/libstore/references.cc
+++ b/src/libstore/references.cc
@@ -1,3 +1,7 @@
+#include "references.hh"
+#include "hash.hh"
+#include "util.hh"
+
 #include <cerrno>
 #include <map>
 
@@ -7,8 +11,8 @@
 #include <dirent.h>
 #include <fcntl.h>
 
-#include "references.hh"
-#include "hash.hh"
+
+namespace nix {
 
 
 static unsigned int refLength = 32; /* characters */
@@ -90,7 +94,7 @@ void checkPath(const string & path,
 
 PathSet scanForReferences(const string & path, const PathSet & paths)
 {
-    map<string, Path> backMap;
+    std::map<string, Path> backMap;
     StringSet ids;
     StringSet seen;
 
@@ -114,10 +118,13 @@ PathSet scanForReferences(const string & path, const PathSet & paths)
 
     PathSet found;
     for (StringSet::iterator i = seen.begin(); i != seen.end(); i++) {
-        map<string, Path>::iterator j;
+        std::map<string, Path>::iterator j;
         if ((j = backMap.find(*i)) == backMap.end()) abort();
         found.insert(j->second);
     }
 
     return found;
 }
+
+ 
+}
diff --git a/src/libstore/references.hh b/src/libstore/references.hh
index 4b1299e7a352..76a7ee166dbe 100644
--- a/src/libstore/references.hh
+++ b/src/libstore/references.hh
@@ -1,10 +1,12 @@
 #ifndef __REFERENCES_H
 #define __REFERENCES_H
 
-#include "util.hh"
+#include "types.hh"
 
+namespace nix {
 
 PathSet scanForReferences(const Path & path, const PathSet & refs);
-
+    
+}
 
 #endif /* !__REFERENCES_H */
diff --git a/src/libstore/store.cc b/src/libstore/store.cc
index 2f9193749347..f8441af9cb42 100644
--- a/src/libstore/store.cc
+++ b/src/libstore/store.cc
@@ -1,3 +1,13 @@
+#include "store.hh"
+#include "util.hh"
+#include "globals.hh"
+#include "db.hh"
+#include "archive.hh"
+#include "pathlocks.hh"
+#include "gc.hh"
+#include "aterm.hh"
+#include "derivations-ast.hh"
+    
 #include <iostream>
 #include <algorithm>
 
@@ -6,14 +16,9 @@
 #include <unistd.h>
 #include <utime.h>
 
-#include "store.hh"
-#include "globals.hh"
-#include "db.hh"
-#include "archive.hh"
-#include "pathlocks.hh"
-#include "gc.hh"
-
+namespace nix {
 
+    
 /* Nix database. */
 static Database nixDB;
 
@@ -956,10 +961,6 @@ void verifyStore(bool checkContents)
 }
 
 
-#include "aterm.hh"
-#include "derivations-ast.hh"
-
-
 /* Upgrade from schema 1 (Nix <= 0.7) to schema 2 (Nix >= 0.8). */
 static void upgradeStore07()
 {
@@ -971,7 +972,7 @@ static void upgradeStore07()
     nixDB.enumTable(txn, dbValidPaths, validPaths2);
     PathSet validPaths(validPaths2.begin(), validPaths2.end());
 
-    cerr << "hashing paths...";
+    std::cerr << "hashing paths...";
     int n = 0;
     for (PathSet::iterator i = validPaths.begin(); i != validPaths.end(); ++i) {
         checkInterrupt();
@@ -980,20 +981,20 @@ static void upgradeStore07()
         if (s == "") {
             Hash hash = hashPath(htSHA256, *i);
             setHash(txn, *i, hash);
-            cerr << ".";
+            std::cerr << ".";
             if (++n % 1000 == 0) {
                 txn.commit();
                 txn.begin(nixDB);
             }
         }
     }
-    cerr << "\n";
+    std::cerr << std::endl;
 
     txn.commit();
 
     txn.begin(nixDB);
     
-    cerr << "processing closures...";
+    std::cerr << "processing closures...";
     for (PathSet::iterator i = validPaths.begin(); i != validPaths.end(); ++i) {
         checkInterrupt();
         if (i->size() > 6 && string(*i, i->size() - 6) == ".store") {
@@ -1037,10 +1038,10 @@ static void upgradeStore07()
                     setReferences(txn, path, references);
             }
             
-            cerr << ".";
+            std::cerr << ".";
         }
     }
-    cerr << "\n";
+    std::cerr << std::endl;
 
     /* !!! maybe this transaction is way too big */
     txn.commit();
@@ -1061,7 +1062,7 @@ static void upgradeStore09()
 
     Transaction txn(nixDB);
 
-    cerr << "converting referers to referrers...";
+    std::cerr << "converting referers to referrers...";
 
     TableId dbReferers = nixDB.openTable("referers"); /* sic! */
 
@@ -1080,16 +1081,19 @@ static void upgradeStore09()
         if (++n % 1000 == 0) {
             txn.commit();
             txn.begin(nixDB);
-            cerr << "|";
+            std::cerr << "|";
         }
-        cerr << ".";
+        std::cerr << ".";
     }
 
     txn.commit();
     
-    cerr << "\n";
+    std::cerr << std::endl;
 
     nixDB.closeTable(dbReferers);
 
     nixDB.deleteTable("referers");
 }
+
+ 
+}
diff --git a/src/libstore/store.hh b/src/libstore/store.hh
index a170c69e7477..7b18871e4f27 100644
--- a/src/libstore/store.hh
+++ b/src/libstore/store.hh
@@ -4,9 +4,12 @@
 #include <string>
 
 #include "hash.hh"
-#include "db.hh"
 
-using namespace std;
+
+namespace nix {
+
+
+class Transaction;
 
 
 /* Nix store and database schema version.  Version 1 (or 0) was Nix <=
@@ -168,5 +171,8 @@ void deleteFromStore(const Path & path, unsigned long long & bytesFreed);
 
 void verifyStore(bool checkContents);
 
+ 
+}
+
 
 #endif /* !__STORE_H */