diff options
author | 2016-07-20 10:00:44 +0000 | |
---|---|---|
committer | 2016-07-20 15:00:40 +0000 | |
commit | 6b747eea2c317285d600278c0720fd4ca7a67546 (patch) | |
tree | c6121f560cd81c6a3334b08f2c6f8894061ef7ac /src | |
parent | 609e876996361fba2341a6f5f4ebfdc794849871 (diff) |
Mark output_base and output_user_root to not be backed up by TimeMachine on Darwin.
This is equivalent to what Xcode does with the directories that it generates as part its builds.
fix for https://github.com/bazelbuild/bazel/issues/1514
--
MOS_MIGRATED_REVID=127927131
Diffstat (limited to 'src')
-rw-r--r-- | src/main/cpp/blaze.cc | 17 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_darwin.cc | 26 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_freebsd.cc | 4 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_linux.cc | 4 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_mingw.cc | 4 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_platform.h | 3 |
6 files changed, 51 insertions, 7 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc index 579a98a783..a17f86d0de 100644 --- a/src/main/cpp/blaze.cc +++ b/src/main/cpp/blaze.cc @@ -1656,28 +1656,29 @@ static void ComputeBaseDirectories(const string &self_path) { } struct stat buf; - if (stat(globals->options.output_base.c_str(), &buf) == -1) { + const char *output_base = globals->options.output_base.c_str(); + if (stat(output_base, &buf) == -1) { if (MakeDirectories(globals->options.output_base, 0777) == -1) { pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "Output base directory '%s' could not be created", - globals->options.output_base.c_str()); + output_base); } } else { if (!S_ISDIR(buf.st_mode)) { die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "Error: Output base directory '%s' could not be created. " "It exists but is not a directory.", - globals->options.output_base.c_str()); + output_base); } } - if (access(globals->options.output_base.c_str(), R_OK | W_OK | X_OK) != 0) { + if (access(output_base, R_OK | W_OK | X_OK) != 0) { die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "Error: Output base directory '%s' must be readable and writable.", - globals->options.output_base.c_str()); + output_base); } + ExcludePathFromBackup(output_base); - globals->options.output_base = - MakeCanonical(globals->options.output_base.c_str()); + globals->options.output_base = MakeCanonical(output_base); globals->lockfile = globals->options.output_base + "/lock"; globals->jvm_log_file = globals->options.output_base + "/server/jvm.out"; } @@ -1810,6 +1811,8 @@ static void CreateSecureOutputRoot() { die(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR, "'%s' is not a directory", root); } + + ExcludePathFromBackup(root); } // TODO(bazel-team): Execute the server as a child process and write its exit diff --git a/src/main/cpp/blaze_util_darwin.cc b/src/main/cpp/blaze_util_darwin.cc index d926cf2ea5..0cadc41660 100644 --- a/src/main/cpp/blaze_util_darwin.cc +++ b/src/main/cpp/blaze_util_darwin.cc @@ -204,4 +204,30 @@ bool KillServerProcess( return true; } +// Sets a flag on path to exclude the path from Apple's automatic backup service +// (Time Machine) +void ExcludePathFromBackup(const string &path) { + CFScopedReleaser<CFURLRef> cf_url(CFURLCreateFromFileSystemRepresentation( + kCFAllocatorDefault, reinterpret_cast<const UInt8 *>(path.c_str()), + path.length(), true)); + if (!cf_url.isValid()) { + fprintf(stderr, "Warning: unable to exclude '%s' from backups\n", + path.c_str()); + return; + } + CFErrorRef cf_error = NULL; + if (!CFURLSetResourcePropertyForKey(cf_url, kCFURLIsExcludedFromBackupKey, + kCFBooleanTrue, &cf_error)) { + CFScopedReleaser<CFErrorRef> cf_error_releaser(cf_error); + string error_desc = DescriptionFromCFError(cf_error_releaser); + fprintf(stderr, "Warning: unable to exclude '%s' from backups", + path.c_str()); + if (error_desc.length() > 0) { + fprintf(stderr, " - '%s'", error_desc.c_str()); + } + fprintf(stderr, "\n"); + return; + } +} + } // namespace blaze. diff --git a/src/main/cpp/blaze_util_freebsd.cc b/src/main/cpp/blaze_util_freebsd.cc index d09d084f38..917a5095bd 100644 --- a/src/main/cpp/blaze_util_freebsd.cc +++ b/src/main/cpp/blaze_util_freebsd.cc @@ -165,4 +165,8 @@ bool KillServerProcess( return true; } +// Not supported. +void ExcludePathFromBackup(const string &path) { +} + } // namespace blaze diff --git a/src/main/cpp/blaze_util_linux.cc b/src/main/cpp/blaze_util_linux.cc index aea194350d..27ab344159 100644 --- a/src/main/cpp/blaze_util_linux.cc +++ b/src/main/cpp/blaze_util_linux.cc @@ -254,4 +254,8 @@ bool KillServerProcess( return true; } +// Not supported. +void ExcludePathFromBackup(const string &path) { +} + } // namespace blaze diff --git a/src/main/cpp/blaze_util_mingw.cc b/src/main/cpp/blaze_util_mingw.cc index 6b79f60638..20d1ea6876 100644 --- a/src/main/cpp/blaze_util_mingw.cc +++ b/src/main/cpp/blaze_util_mingw.cc @@ -780,4 +780,8 @@ bool KillServerProcess( return result; } +// Not supported. +void ExcludePathFromBackup(const string &path) { +} + } // namespace blaze diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h index c6e1d700a9..1497a85824 100644 --- a/src/main/cpp/blaze_util_platform.h +++ b/src/main/cpp/blaze_util_platform.h @@ -129,6 +129,9 @@ void ReleaseLock(BlazeLock* blaze_lock); bool KillServerProcess( int pid, const string& output_base, const string& install_base); +// Mark path as being excluded from backups (if supported by operating system). +void ExcludePathFromBackup(const string &path); + } // namespace blaze #endif // BAZEL_SRC_MAIN_CPP_BLAZE_UTIL_PLATFORM_H_ |