Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: base/files/file_util_mac.mm

Issue 2724733002: Revert of Allow $TMPDIR to set temporary directory on OS X. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/file_select_helper_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <copyfile.h>
7 #import <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
8 #include <copyfile.h>
9 #include <stdlib.h>
10 9
11 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
12 #include "base/mac/foundation_util.h" 11 #include "base/mac/foundation_util.h"
13 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
14 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
15 14
16 namespace base { 15 namespace base {
17 16
18 bool CopyFile(const FilePath& from_path, const FilePath& to_path) { 17 bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
19 ThreadRestrictions::AssertIOAllowed(); 18 ThreadRestrictions::AssertIOAllowed();
20 if (from_path.ReferencesParent() || to_path.ReferencesParent()) 19 if (from_path.ReferencesParent() || to_path.ReferencesParent())
21 return false; 20 return false;
22 return (copyfile(from_path.value().c_str(), 21 return (copyfile(from_path.value().c_str(),
23 to_path.value().c_str(), NULL, COPYFILE_DATA) == 0); 22 to_path.value().c_str(), NULL, COPYFILE_DATA) == 0);
24 } 23 }
25 24
26 bool GetTempDir(base::FilePath* path) { 25 bool GetTempDir(base::FilePath* path) {
27 // In order to facilitate hermetic runs on macOS, first check $TMPDIR.
28 // NOTE: $TMPDIR is ALMOST ALWAYS set on macOS (unless the user un-set it).
29 const char* env_tmpdir = getenv("TMPDIR");
30 if (env_tmpdir) {
31 *path = base::FilePath(env_tmpdir);
32 return true;
33 }
34
35 // If we didn't find it, fall back to the native function.
36 NSString* tmp = NSTemporaryDirectory(); 26 NSString* tmp = NSTemporaryDirectory();
37 if (tmp == nil) 27 if (tmp == nil)
38 return false; 28 return false;
39 *path = base::mac::NSStringToFilePath(tmp); 29 *path = base::mac::NSStringToFilePath(tmp);
40 return true; 30 return true;
41 } 31 }
42 32
43 FilePath GetHomeDir() { 33 FilePath GetHomeDir() {
44 NSString* tmp = NSHomeDirectory(); 34 NSString* tmp = NSHomeDirectory();
45 if (tmp != nil) { 35 if (tmp != nil) {
46 FilePath mac_home_dir = base::mac::NSStringToFilePath(tmp); 36 FilePath mac_home_dir = base::mac::NSStringToFilePath(tmp);
47 if (!mac_home_dir.empty()) 37 if (!mac_home_dir.empty())
48 return mac_home_dir; 38 return mac_home_dir;
49 } 39 }
50 40
51 // Fall back on temp dir if no home directory is defined. 41 // Fall back on temp dir if no home directory is defined.
52 FilePath rv; 42 FilePath rv;
53 if (GetTempDir(&rv)) 43 if (GetTempDir(&rv))
54 return rv; 44 return rv;
55 45
56 // Last resort. 46 // Last resort.
57 return FilePath("/tmp"); 47 return FilePath("/tmp");
58 } 48 }
59 49
60 } // namespace base 50 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/file_select_helper_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698