aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-10-10 12:54:37 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-10-10 12:54:37 +0200
commite99bb9121787ae30a1872f63b326ce5c130ec7ef (patch)
treeecdd2b7ba575b0848d2770f8e74b40646f512c71 /src/libstore
parentd343c03edb8d4d2be7aca4f1a377544b3889b8b3 (diff)
parentc3aaf3b8da1a925c569389f13a861816a781a3c8 (diff)
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/build.cc11
-rw-r--r--src/libstore/builtins/buildenv.cc3
-rw-r--r--src/libstore/local-store.cc32
-rw-r--r--src/libstore/local-store.hh2
-rw-r--r--src/libstore/local.mk5
-rw-r--r--src/libstore/misc.cc9
-rw-r--r--src/libstore/references.cc3
-rw-r--r--src/libstore/store-api.cc3
-rw-r--r--src/libstore/store-api.hh3
9 files changed, 43 insertions, 28 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 53e357435..cdf848c98 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -568,10 +568,9 @@ UserLock::UserLock()
{
auto lockedPaths(lockedPaths_.lock());
- if (lockedPaths->count(fnUserLock))
+ if (!lockedPaths->insert(fnUserLock).second)
/* We already have a lock on this one. */
continue;
- lockedPaths->insert(fnUserLock);
}
try {
@@ -620,8 +619,8 @@ UserLock::UserLock()
UserLock::~UserLock()
{
auto lockedPaths(lockedPaths_.lock());
- assert(lockedPaths->count(fnUserLock));
- lockedPaths->erase(fnUserLock);
+ auto erased = lockedPaths->erase(fnUserLock);
+ assert(erased);
}
@@ -1125,10 +1124,8 @@ void DerivationGoal::addWantedOutputs(const StringSet & outputs)
needRestart = true;
} else
for (auto & i : outputs)
- if (wantedOutputs.find(i) == wantedOutputs.end()) {
- wantedOutputs.insert(i);
+ if (wantedOutputs.insert(i).second)
needRestart = true;
- }
}
diff --git a/src/libstore/builtins/buildenv.cc b/src/libstore/builtins/buildenv.cc
index 74e706664..096593886 100644
--- a/src/libstore/builtins/buildenv.cc
+++ b/src/libstore/builtins/buildenv.cc
@@ -123,8 +123,7 @@ static Path out;
static void addPkg(const Path & pkgDir, int priority)
{
- if (done.count(pkgDir)) return;
- done.insert(pkgDir);
+ if (!done.insert(pkgDir).second) return;
createLinks(pkgDir, out, priority);
try {
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 307c00dbb..6bc3079a5 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -70,15 +70,17 @@ LocalStore::LocalStore(const Params & params)
createSymlink(profilesDir, gcRootsDir + "/profiles");
}
+ for (auto & perUserDir : {profilesDir + "/per-user", gcRootsDir + "/per-user"}) {
+ createDirs(perUserDir);
+ if (chmod(perUserDir.c_str(), 0755) == -1)
+ throw SysError("could not set permissions on '%s' to 755", perUserDir);
+ }
+
+ createUser(getUserName(), getuid());
+
/* Optionally, create directories and set permissions for a
multi-user install. */
if (getuid() == 0 && settings.buildUsersGroup != "") {
-
- Path perUserDir = profilesDir + "/per-user";
- createDirs(perUserDir);
- if (chmod(perUserDir.c_str(), 01777) == -1)
- throw SysError(format("could not set permissions on '%1%' to 1777") % perUserDir);
-
mode_t perm = 01775;
struct group * gr = getgrnam(settings.buildUsersGroup.get().c_str());
@@ -1285,8 +1287,7 @@ void LocalStore::verifyPath(const Path & path, const PathSet & store,
{
checkInterrupt();
- if (done.find(path) != done.end()) return;
- done.insert(path);
+ if (!done.insert(path).second) return;
if (!isStorePath(path)) {
printError(format("path '%1%' is not in the Nix store") % path);
@@ -1426,4 +1427,19 @@ void LocalStore::signPathInfo(ValidPathInfo & info)
}
+void LocalStore::createUser(const std::string & userName, uid_t userId)
+{
+ for (auto & dir : {
+ fmt("%s/profiles/per-user/%s", stateDir, userName),
+ fmt("%s/gcroots/per-user/%s", stateDir, userName)
+ }) {
+ createDirs(dir);
+ if (chmod(dir.c_str(), 0755) == -1)
+ throw SysError("changing permissions of directory '%s'", dir);
+ if (chown(dir.c_str(), userId, getgid()) == -1)
+ throw SysError("changing owner of directory '%s'", dir);
+ }
+}
+
+
}
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index 3ae34c403..379a06af8 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -293,6 +293,8 @@ private:
Path getRealStoreDir() override { return realStoreDir; }
+ void createUser(const std::string & userName, uid_t userId) override;
+
friend class DerivationGoal;
friend class SubstitutionGoal;
};
diff --git a/src/libstore/local.mk b/src/libstore/local.mk
index 89fc918c3..d690fea28 100644
--- a/src/libstore/local.mk
+++ b/src/libstore/local.mk
@@ -39,9 +39,12 @@ libstore_CXXFLAGS = \
-DNIX_LIBEXEC_DIR=\"$(libexecdir)\" \
-DNIX_BIN_DIR=\"$(bindir)\" \
-DNIX_MAN_DIR=\"$(mandir)\" \
- -DSANDBOX_SHELL="\"$(sandbox_shell)\"" \
-DLSOF=\"$(lsof)\"
+ifneq ($(sandbox_shell),)
+libstore_CXXFLAGS += -DSANDBOX_SHELL="\"$(sandbox_shell)\""
+endif
+
$(d)/local-store.cc: $(d)/schema.sql.gen.hh
$(d)/build.cc:
diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc
index dddf13430..05b93d4c9 100644
--- a/src/libstore/misc.cc
+++ b/src/libstore/misc.cc
@@ -29,8 +29,7 @@ void Store::computeFSClosure(const PathSet & startPaths,
{
auto state(state_.lock());
if (state->exc) return;
- if (state->paths.count(path)) return;
- state->paths.insert(path);
+ if (!state->paths.insert(path).second) return;
state->pending++;
}
@@ -175,8 +174,7 @@ void Store::queryMissing(const PathSet & targets,
{
auto state(state_.lock());
- if (state->done.count(path)) return;
- state->done.insert(path);
+ if (!state->done.insert(path).second) return;
}
DrvPathWithOutputs i2 = parseDrvPathWithOutputs(path);
@@ -252,8 +250,7 @@ Paths Store::topoSortPaths(const PathSet & paths)
if (parents.find(path) != parents.end())
throw BuildError(format("cycle detected in the references of '%1%' from '%2%'") % path % *parent);
- if (visited.find(path) != visited.end()) return;
- visited.insert(path);
+ if (!visited.insert(path).second) return;
parents.insert(path);
PathSet references;
diff --git a/src/libstore/references.cc b/src/libstore/references.cc
index 5b7eb1f84..0dcc264c3 100644
--- a/src/libstore/references.cc
+++ b/src/libstore/references.cc
@@ -36,11 +36,10 @@ static void search(const unsigned char * s, size_t len,
}
if (!match) continue;
string ref((const char *) s + i, refLength);
- if (hashes.find(ref) != hashes.end()) {
+ if (hashes.erase(ref)) {
debug(format("found reference to '%1%' at offset '%2%'")
% ref % i);
seen.insert(ref);
- hashes.erase(ref);
}
++i;
}
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index e8c1c1fdd..d0ef4e95b 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -949,8 +949,7 @@ std::list<ref<Store>> getDefaultSubstituters()
StringSet done;
auto addStore = [&](const std::string & uri) {
- if (done.count(uri)) return;
- done.insert(uri);
+ if (!done.insert(uri).second) return;
try {
stores.push_back(openStore(uri));
} catch (Error & e) {
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 5733bd9de..a9b073be4 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -629,6 +629,9 @@ public:
return storePath;
}
+ virtual void createUser(const std::string & userName, uid_t userId)
+ { }
+
protected:
Stats stats;