From aa7653608d4d0028bb98af491aec76b2fea7f882 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 30 Oct 2023 17:03:06 +0100 Subject: [PATCH] Minor cleanup in libexpr/flake/flake.cc (cherry picked from commit 05316d401fa509557c71140e17bb19814412fcb8) Change-Id: I6ba0b55709f5fe21beb4e9f3bf72ee28715d15f3 --- src/libexpr/flake/flake.cc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index 20d7878e9..d96f2b22e 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -645,29 +645,28 @@ LockedFlake lockFlake( auto newLockFileS = fmt("%s\n", newLockFile); - if (lockFlags.outputLockFilePath) + if (lockFlags.outputLockFilePath) { + if (lockFlags.commitLockFile) + throw Error("'--commit-lock-file' and '--output-lock-file' are incompatible"); writeFile(*lockFlags.outputLockFilePath, newLockFileS); - else { + } else { auto relPath = (topRef.subdir == "" ? "" : topRef.subdir + "/") + "flake.lock"; - auto outputLockFilePath = sourcePath ? std::optional{*sourcePath + "/" + relPath} : std::nullopt; + auto outputLockFilePath = *sourcePath + "/" + relPath; - bool lockFileExists = pathExists(*outputLockFilePath); + bool lockFileExists = pathExists(outputLockFilePath); if (lockFileExists) { auto s = chomp(diff); if (s.empty()) - warn("updating lock file '%s'", *outputLockFilePath); + warn("updating lock file '%s'", outputLockFilePath); else - warn("updating lock file '%s':\n%s", *outputLockFilePath, s); + warn("updating lock file '%s':\n%s", outputLockFilePath, s); } else - warn("creating lock file '%s'", *outputLockFilePath); + warn("creating lock file '%s'", outputLockFilePath); std::optional commitMessage = std::nullopt; if (lockFlags.commitLockFile) { - if (lockFlags.outputLockFilePath) { - throw Error("--commit-lock-file and --output-lock-file are currently incompatible"); - } std::string cm; cm = fetchSettings.commitLockFileSummary.get();