aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Dmitry Lomov <dslomov@google.com>2016-04-15 14:05:24 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-04-15 14:10:05 +0000
commitbc84cc868c3598c284304db923aead1040787e5d (patch)
treef59a5b047b6066fc565a3c02b404c400d78c6bc4 /src
parent7a3abbecea9b02a711262527e10407dd76821252 (diff)
Make output base on Windows shorter.
This hashes together a user name and an workspace directory, and uses less bits from MD5 hash to make the path much shorter. -- MOS_MIGRATED_REVID=119952145
Diffstat (limited to 'src')
-rw-r--r--src/main/cpp/blaze.cc34
-rw-r--r--src/main/cpp/blaze_util_mingw.cc7
2 files changed, 40 insertions, 1 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 20f4ae57ee..0d45f2f934 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -127,6 +127,34 @@ static string GetHashedBaseDir(const string &root,
return root + "/" + digest.String();
}
+// Builds a shorter output base dir name for Windows.
+// This MD5s together user name and workspace directory,
+// and only uses 1/3 of the bits to get 8-char alphanumeric
+// file name.
+static string GetHashedBaseDirForWindows(const string &root,
+ const string &product_name,
+ const string &user_name,
+ const string &workspace_directory) {
+ static const char* alphabet
+ // Exactly 64 characters.
+ = "abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789$-";
+
+ // The length of the resulting filename (8 characters).
+ static const int filename_length = Md5Digest::kDigestLength / 2;
+ unsigned char buf[Md5Digest::kDigestLength];
+ char coded_name[filename_length + 1];
+ Md5Digest digest;
+ digest.Update(user_name.data(), user_name.size());
+ digest.Update(workspace_directory.data(), workspace_directory.size());
+ digest.Finish(buf);
+ for (int i = 0; i < filename_length; i++) {
+ coded_name[i] = alphabet[buf[i] & 0x3F];
+ }
+ coded_name[filename_length] = '\0';
+ return root + "/" + product_name + "/" + string(coded_name);
+}
+
+
// A devtools_ijar::ZipExtractorProcessor to extract the InstallKeyFile
class GetInstallKeyFileProcessor : public devtools_ijar::ZipExtractorProcessor {
public:
@@ -1465,8 +1493,14 @@ static void ComputeBaseDirectories(const string &self_path) {
}
if (globals->options.output_base.empty()) {
+#if !defined(__CYGWIN__)
globals->options.output_base = GetHashedBaseDir(
globals->options.output_user_root, globals->workspace);
+#else
+ globals->options.output_base = GetHashedBaseDirForWindows(
+ blaze::GetOutputRoot(), globals->options.GetProductName(),
+ blaze::GetUserName(), globals->workspace);
+#endif
}
struct stat buf;
diff --git a/src/main/cpp/blaze_util_mingw.cc b/src/main/cpp/blaze_util_mingw.cc
index c959f00f6d..e27ae18a92 100644
--- a/src/main/cpp/blaze_util_mingw.cc
+++ b/src/main/cpp/blaze_util_mingw.cc
@@ -51,7 +51,12 @@ string GetSelfPath() {
}
string GetOutputRoot() {
- return "/var/tmp";
+ char* tmpdir = getenv("TMPDIR");
+ if (tmpdir == 0 || strlen(tmpdir) == 0) {
+ return "/var/tmp";
+ } else {
+ return string(tmpdir);
+ }
}
pid_t GetPeerProcessId(int socket) {