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 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
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 namespace internal { | |
18 | 17 |
19 bool CopyFileUnsafe(const FilePath& from_path, const FilePath& to_path) { | 18 bool CopyFile(const FilePath& from_path, const FilePath& to_path) { |
20 ThreadRestrictions::AssertIOAllowed(); | 19 ThreadRestrictions::AssertIOAllowed(); |
| 20 if (from_path.ReferencesParent() || to_path.ReferencesParent()) |
| 21 return false; |
21 return (copyfile(from_path.value().c_str(), | 22 return (copyfile(from_path.value().c_str(), |
22 to_path.value().c_str(), NULL, COPYFILE_DATA) == 0); | 23 to_path.value().c_str(), NULL, COPYFILE_DATA) == 0); |
23 } | 24 } |
24 | 25 |
25 } // namespace internal | |
26 | |
27 bool GetTempDir(base::FilePath* path) { | 26 bool GetTempDir(base::FilePath* path) { |
28 NSString* tmp = NSTemporaryDirectory(); | 27 NSString* tmp = NSTemporaryDirectory(); |
29 if (tmp == nil) | 28 if (tmp == nil) |
30 return false; | 29 return false; |
31 *path = base::mac::NSStringToFilePath(tmp); | 30 *path = base::mac::NSStringToFilePath(tmp); |
32 return true; | 31 return true; |
33 } | 32 } |
34 | 33 |
35 FilePath GetHomeDir() { | 34 FilePath GetHomeDir() { |
36 NSString* tmp = NSHomeDirectory(); | 35 NSString* tmp = NSHomeDirectory(); |
37 if (tmp != nil) { | 36 if (tmp != nil) { |
38 FilePath mac_home_dir = base::mac::NSStringToFilePath(tmp); | 37 FilePath mac_home_dir = base::mac::NSStringToFilePath(tmp); |
39 if (!mac_home_dir.empty()) | 38 if (!mac_home_dir.empty()) |
40 return mac_home_dir; | 39 return mac_home_dir; |
41 } | 40 } |
42 | 41 |
43 // Fall back on temp dir if no home directory is defined. | 42 // Fall back on temp dir if no home directory is defined. |
44 FilePath rv; | 43 FilePath rv; |
45 if (GetTempDir(&rv)) | 44 if (GetTempDir(&rv)) |
46 return rv; | 45 return rv; |
47 | 46 |
48 // Last resort. | 47 // Last resort. |
49 return FilePath("/tmp"); | 48 return FilePath("/tmp"); |
50 } | 49 } |
51 | 50 |
52 } // namespace base | 51 } // namespace base |
OLD | NEW |