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 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 | 17 |
18 bool CopyFile(const FilePath& from_path, const FilePath& to_path) { | 18 bool CopyFile(const FilePath& from_path, const FilePath& to_path) { |
19 ThreadRestrictions::AssertIOAllowed(); | 19 ThreadRestrictions::AssertIOAllowed(); |
20 if (from_path.ReferencesParent() || to_path.ReferencesParent()) | 20 if (from_path.ReferencesParent() || to_path.ReferencesParent()) |
21 return false; | 21 return false; |
22 return (copyfile(from_path.value().c_str(), | 22 return (copyfile(from_path.value().c_str(), |
23 to_path.value().c_str(), NULL, COPYFILE_DATA) == 0); | 23 to_path.value().c_str(), NULL, COPYFILE_DATA) == 0); |
24 } | 24 } |
25 | 25 |
26 bool GetTempDir(base::FilePath* path) { | 26 bool GetTempDir(base::FilePath* path) { |
27 // In order to facilitate hermetic runs on macOS, first check $TMPDIR. | 27 // 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). | 28 // $MAC_CHROMIUM_TMPDIR. |
Mark Mentovai
2017/03/27 20:36:31
Explain why not TMPDIR here, since it’s a natural
| |
29 const char* env_tmpdir = getenv("TMPDIR"); | 29 const char* env_tmpdir = getenv("MAC_CHROMIUM_TMPDIR"); |
iannucci
2017/03/25 00:45:04
I don't have strong feelings about this name.. if
Mark Mentovai
2017/03/27 20:36:31
Maybe [D]CHECK that the length is within a reasona
| |
30 if (env_tmpdir) { | 30 if (env_tmpdir) { |
31 *path = base::FilePath(env_tmpdir); | 31 *path = base::FilePath(env_tmpdir); |
32 return true; | 32 return true; |
33 } | 33 } |
34 | 34 |
35 // If we didn't find it, fall back to the native function. | 35 // If we didn't find it, fall back to the native function. |
36 NSString* tmp = NSTemporaryDirectory(); | 36 NSString* tmp = NSTemporaryDirectory(); |
37 if (tmp == nil) | 37 if (tmp == nil) |
38 return false; | 38 return false; |
39 *path = base::mac::NSStringToFilePath(tmp); | 39 *path = base::mac::NSStringToFilePath(tmp); |
(...skipping 11 matching lines...) Expand all Loading... | |
51 // Fall back on temp dir if no home directory is defined. | 51 // Fall back on temp dir if no home directory is defined. |
52 FilePath rv; | 52 FilePath rv; |
53 if (GetTempDir(&rv)) | 53 if (GetTempDir(&rv)) |
54 return rv; | 54 return rv; |
55 | 55 |
56 // Last resort. | 56 // Last resort. |
57 return FilePath("/tmp"); | 57 return FilePath("/tmp"); |
58 } | 58 } |
59 | 59 |
60 } // namespace base | 60 } // namespace base |
OLD | NEW |