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

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

Issue 2770753006: [base/files] Respect MAC_CHROMIUM_TMPDIR instead of TMPDIR on macOS. (Closed)
Patch Set: feedback 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 | no next file » | 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"
6
7 #import <Foundation/Foundation.h> 5 #import <Foundation/Foundation.h>
8 #include <copyfile.h> 6 #include <copyfile.h>
9 #include <stdlib.h> 7 #include <stdlib.h>
10 8
11 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
Mark Mentovai 2017/03/28 00:20:23 This was correct where it was before.
iannucci 2017/03/28 00:24:04 Presumit was hollering at me about this (my origin
Mark Mentovai 2017/03/28 00:27:14 Presubmit’s wrong, NOPRESUBMIT it if you have to,
11 #include "base/logging.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. We check this instead of $TMPDIR because external
29 const char* env_tmpdir = getenv("TMPDIR"); 29 // programs currently set $TMPDIR with no effect, but when we respect it
30 // directly it can cause crashes (like crbug.com/698759).
31 const char* env_tmpdir = getenv("MAC_CHROMIUM_TMPDIR");
30 if (env_tmpdir) { 32 if (env_tmpdir) {
33 DCHECK_LT(strlen(env_tmpdir), 50)
iannucci 2017/03/28 00:10:59 NSTemporaryDirectory() length is 49.
Mark Mentovai 2017/03/28 00:20:23 #inclue <string.h> for this.
iannucci 2017/03/28 00:24:04 er... whoops.
34 << "too-long TMPDIR causes socket name length issues.";
31 *path = base::FilePath(env_tmpdir); 35 *path = base::FilePath(env_tmpdir);
32 return true; 36 return true;
33 } 37 }
34 38
35 // If we didn't find it, fall back to the native function. 39 // If we didn't find it, fall back to the native function.
36 NSString* tmp = NSTemporaryDirectory(); 40 NSString* tmp = NSTemporaryDirectory();
37 if (tmp == nil) 41 if (tmp == nil)
38 return false; 42 return false;
39 *path = base::mac::NSStringToFilePath(tmp); 43 *path = base::mac::NSStringToFilePath(tmp);
40 return true; 44 return true;
(...skipping 10 matching lines...) Expand all
51 // Fall back on temp dir if no home directory is defined. 55 // Fall back on temp dir if no home directory is defined.
52 FilePath rv; 56 FilePath rv;
53 if (GetTempDir(&rv)) 57 if (GetTempDir(&rv))
54 return rv; 58 return rv;
55 59
56 // Last resort. 60 // Last resort.
57 return FilePath("/tmp"); 61 return FilePath("/tmp");
58 } 62 }
59 63
60 } // namespace base 64 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698