fix(3p/nix): convert local-store asserts into throws

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>
This commit is contained in:
Kane York 2020-07-23 16:35:51 -07:00 committed by kanepyork
parent 3089f6b6ce
commit 80ff83e698

View file

@ -170,7 +170,7 @@ LocalStore::LocalStore(const Params& params)
if (curSchema == 0) { /* new store */ if (curSchema == 0) { /* new store */
curSchema = nixSchemaVersion; curSchema = nixSchemaVersion;
openDB(*state, true); openDB(*state, true);
writeFile(schemaPath, (format("%1%") % nixSchemaVersion).str()); writeFile(schemaPath, (format("%1%") % curSchema).str());
} else if (curSchema < nixSchemaVersion) { } else if (curSchema < nixSchemaVersion) {
if (curSchema < 5) { if (curSchema < 5) {
throw Error( 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 ensure that we don't fail on hard links within the same build
(i.e. "touch $out/foo; ln $out/foo $out/bar"). */ (i.e. "touch $out/foo; ln $out/foo $out/bar"). */
if (fromUid != (uid_t)-1 && st.st_uid != fromUid) { 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()) { if (inodesSeen.find(Inode(st.st_dev, st.st_ino)) == inodesSeen.end()) {
throw BuildError(format("invalid ownership on file '%1%'") % path); throw BuildError(format("invalid ownership on file '%1%'") % path);
} }
if (!(S_ISLNK(st.st_mode) ||
// `mode` variable is only used in debug builds (st.st_uid == geteuid() &&
#pragma clang diagnostic push ((st.st_mode & ~S_IFMT) == 0444 || (st.st_mode & ~S_IFMT) == 0555) &&
#pragma clang diagnostic ignored "-Wunused-variable" st.st_mtime == mtimeStore))) {
throw BuildError(
mode_t mode = st.st_mode & ~S_IFMT; format("invalid permissions on file '%1%', should be 0444/0555") %
assert(S_ISLNK(st.st_mode) || path);
(st.st_uid == geteuid() && (mode == 0444 || mode == 0555) && }
st.st_mtime == mtimeStore));
#pragma clang diagnostic pop
return; return;
} }