diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc index 6a764b15a52082..9374e05397e224 100644 --- a/src/main/cpp/blaze.cc +++ b/src/main/cpp/blaze.cc @@ -59,6 +59,12 @@ #include #endif +#if !defined(_WIN32) +#include +#else +#include +#endif + #include "src/main/cpp/archive_utils.h" #include "src/main/cpp/blaze_util.h" #include "src/main/cpp/blaze_util_platform.h" @@ -1012,10 +1018,24 @@ static void EnsureCorrectRunningVersion(const StartupOptions &startup_options, std::unique_ptr mtime( blaze_util::CreateFileMtime()); if (!mtime->SetToNow(blaze_util::Path(startup_options.install_base))) { - string err = GetLastErrorString(); - BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR) - << "failed to set timestamp on '" << startup_options.install_base - << "': " << err; + // Ignore permissions errors (i.e. if the install base is not writable): + bool raise_error = true; + +#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__CYGWIN__) + // On POSIX platforms, `SetToNow` is backed by `utime(2)` which can + // return `EROFS`/`EPERM`: + if (errno == EROFS || errno == EPERM) { raise_error = false; } +#elif defined(_WIN32) + // On Windows, `SetToNow` is backed by `CreateFileW` + `SetFileTime`: + if (::GetLastError() == ERROR_ACCESS_DENIED) { raise_error = false; } +#endif + + if (raise_error) { + string err = GetLastErrorString(); + BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR) + << "failed to set timestamp on '" << startup_options.install_base + << "': " << err; + } } } }