about summary refs log tree commit diff
path: root/third_party/nix/src/libstore/local-store.cc
diff options
context:
space:
mode:
authorKane York <kanepyork@gmail.com>2020-07-23T23·35-0700
committerkanepyork <rikingcoding@gmail.com>2020-07-27T20·50+0000
commit80ff83e6986f9c569f1f55b02337ab29fb97e7ca (patch)
tree75aa2a888c6ffe367a7b8dfcb9dcfe3035104644 /third_party/nix/src/libstore/local-store.cc
parent3089f6b6ce84833f669bb523718b20b6ad194105 (diff)
fix(3p/nix): convert local-store asserts into throws r/1493
This fixes a clang-tidy DeadStore warning by turning debug asserts into production checks.

Updates: #11
Change-Id: Ia6e5a4cb1b56594c9844c6bbd3d152f84b426d09
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1409
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'third_party/nix/src/libstore/local-store.cc')
-rw-r--r--third_party/nix/src/libstore/local-store.cc25
1 files changed, 12 insertions, 13 deletions
diff --git a/third_party/nix/src/libstore/local-store.cc b/third_party/nix/src/libstore/local-store.cc
index 5ae38535d841..8c0a28a61647 100644
--- a/third_party/nix/src/libstore/local-store.cc
+++ b/third_party/nix/src/libstore/local-store.cc
@@ -170,7 +170,7 @@ LocalStore::LocalStore(const Params& params)
   if (curSchema == 0) { /* new store */
     curSchema = nixSchemaVersion;
     openDB(*state, true);
-    writeFile(schemaPath, (format("%1%") % nixSchemaVersion).str());
+    writeFile(schemaPath, (format("%1%") % curSchema).str());
   } else if (curSchema < nixSchemaVersion) {
     if (curSchema < 5) {
       throw Error(
@@ -489,21 +489,20 @@ static void canonicalisePathMetaData_(const Path& path, uid_t fromUid,
      ensure that we don't fail on hard links within the same build
      (i.e. "touch $out/foo; ln $out/foo $out/bar"). */
   if (fromUid != (uid_t)-1 && st.st_uid != fromUid) {
-    assert(!S_ISDIR(st.st_mode));
+    if (S_ISDIR(st.st_mode)) {
+      throw BuildError(format("invalid file '%1%': is a directory") % path);
+    }
     if (inodesSeen.find(Inode(st.st_dev, st.st_ino)) == inodesSeen.end()) {
       throw BuildError(format("invalid ownership on file '%1%'") % path);
     }
-
-// `mode` variable is only used in debug builds
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunused-variable"
-
-    mode_t mode = st.st_mode & ~S_IFMT;
-    assert(S_ISLNK(st.st_mode) ||
-           (st.st_uid == geteuid() && (mode == 0444 || mode == 0555) &&
-            st.st_mtime == mtimeStore));
-
-#pragma clang diagnostic pop
+    if (!(S_ISLNK(st.st_mode) ||
+          (st.st_uid == geteuid() &&
+           ((st.st_mode & ~S_IFMT) == 0444 || (st.st_mode & ~S_IFMT) == 0555) &&
+           st.st_mtime == mtimeStore))) {
+      throw BuildError(
+          format("invalid permissions on file '%1%', should be 0444/0555") %
+          path);
+    }
 
     return;
   }