| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/files/file_util.h" | 5 #include "base/files/file_util.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #include <copyfile.h> | 8 #include <copyfile.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> |
| 10 | 11 |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/logging.h" |
| 12 #include "base/mac/foundation_util.h" | 14 #include "base/mac/foundation_util.h" |
| 13 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 14 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 15 | 17 |
| 16 namespace base { | 18 namespace base { |
| 17 | 19 |
| 18 bool CopyFile(const FilePath& from_path, const FilePath& to_path) { | 20 bool CopyFile(const FilePath& from_path, const FilePath& to_path) { |
| 19 ThreadRestrictions::AssertIOAllowed(); | 21 ThreadRestrictions::AssertIOAllowed(); |
| 20 if (from_path.ReferencesParent() || to_path.ReferencesParent()) | 22 if (from_path.ReferencesParent() || to_path.ReferencesParent()) |
| 21 return false; | 23 return false; |
| 22 return (copyfile(from_path.value().c_str(), | 24 return (copyfile(from_path.value().c_str(), |
| 23 to_path.value().c_str(), NULL, COPYFILE_DATA) == 0); | 25 to_path.value().c_str(), NULL, COPYFILE_DATA) == 0); |
| 24 } | 26 } |
| 25 | 27 |
| 26 bool GetTempDir(base::FilePath* path) { | 28 bool GetTempDir(base::FilePath* path) { |
| 27 // In order to facilitate hermetic runs on macOS, first check $TMPDIR. | 29 // In order to facilitate hermetic runs on macOS, first check |
| 28 // NOTE: $TMPDIR is ALMOST ALWAYS set on macOS (unless the user un-set it). | 30 // $MAC_CHROMIUM_TMPDIR. We check this instead of $TMPDIR because external |
| 29 const char* env_tmpdir = getenv("TMPDIR"); | 31 // programs currently set $TMPDIR with no effect, but when we respect it |
| 32 // directly it can cause crashes (like crbug.com/698759). |
| 33 const char* env_tmpdir = getenv("MAC_CHROMIUM_TMPDIR"); |
| 30 if (env_tmpdir) { | 34 if (env_tmpdir) { |
| 35 DCHECK_LT(strlen(env_tmpdir), 50u) |
| 36 << "too-long TMPDIR causes socket name length issues."; |
| 31 *path = base::FilePath(env_tmpdir); | 37 *path = base::FilePath(env_tmpdir); |
| 32 return true; | 38 return true; |
| 33 } | 39 } |
| 34 | 40 |
| 35 // If we didn't find it, fall back to the native function. | 41 // If we didn't find it, fall back to the native function. |
| 36 NSString* tmp = NSTemporaryDirectory(); | 42 NSString* tmp = NSTemporaryDirectory(); |
| 37 if (tmp == nil) | 43 if (tmp == nil) |
| 38 return false; | 44 return false; |
| 39 *path = base::mac::NSStringToFilePath(tmp); | 45 *path = base::mac::NSStringToFilePath(tmp); |
| 40 return true; | 46 return true; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 51 // Fall back on temp dir if no home directory is defined. | 57 // Fall back on temp dir if no home directory is defined. |
| 52 FilePath rv; | 58 FilePath rv; |
| 53 if (GetTempDir(&rv)) | 59 if (GetTempDir(&rv)) |
| 54 return rv; | 60 return rv; |
| 55 | 61 |
| 56 // Last resort. | 62 // Last resort. |
| 57 return FilePath("/tmp"); | 63 return FilePath("/tmp"); |
| 58 } | 64 } |
| 59 | 65 |
| 60 } // namespace base | 66 } // namespace base |
| OLD | NEW |