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/test/test_file_util.h" | 5 #include "base/test/test_file_util.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 | 19 |
| 20 using base::MakeAbsoluteFilePath; |
| 21 |
20 namespace file_util { | 22 namespace file_util { |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 // Deny |permission| on the file |path|. | 26 // Deny |permission| on the file |path|. |
25 bool DenyFilePermission(const base::FilePath& path, mode_t permission) { | 27 bool DenyFilePermission(const base::FilePath& path, mode_t permission) { |
26 struct stat stat_buf; | 28 struct stat stat_buf; |
27 if (stat(path.value().c_str(), &stat_buf) != 0) | 29 if (stat(path.value().c_str(), &stat_buf) != 0) |
28 return false; | 30 return false; |
29 stat_buf.st_mode &= ~permission; | 31 stat_buf.st_mode &= ~permission; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 const base::FilePath& dest_dir) { | 85 const base::FilePath& dest_dir) { |
84 char top_dir[PATH_MAX]; | 86 char top_dir[PATH_MAX]; |
85 if (base::strlcpy(top_dir, source_dir.value().c_str(), | 87 if (base::strlcpy(top_dir, source_dir.value().c_str(), |
86 arraysize(top_dir)) >= arraysize(top_dir)) { | 88 arraysize(top_dir)) >= arraysize(top_dir)) { |
87 return false; | 89 return false; |
88 } | 90 } |
89 | 91 |
90 // This function does not properly handle destinations within the source | 92 // This function does not properly handle destinations within the source |
91 base::FilePath real_to_path = dest_dir; | 93 base::FilePath real_to_path = dest_dir; |
92 if (PathExists(real_to_path)) { | 94 if (PathExists(real_to_path)) { |
93 if (!AbsolutePath(&real_to_path)) | 95 real_to_path = MakeAbsoluteFilePath(real_to_path); |
| 96 if (real_to_path.empty()) |
94 return false; | 97 return false; |
95 } else { | 98 } else { |
96 real_to_path = real_to_path.DirName(); | 99 real_to_path = MakeAbsoluteFilePath(real_to_path.DirName()); |
97 if (!AbsolutePath(&real_to_path)) | 100 if (real_to_path.empty()) |
98 return false; | 101 return false; |
99 } | 102 } |
100 if (real_to_path.value().compare(0, source_dir.value().size(), | 103 if (real_to_path.value().compare(0, source_dir.value().size(), |
101 source_dir.value()) == 0) | 104 source_dir.value()) == 0) |
102 return false; | 105 return false; |
103 | 106 |
104 bool success = true; | 107 bool success = true; |
105 int traverse_type = FileEnumerator::FILES | | 108 int traverse_type = FileEnumerator::FILES | |
106 FileEnumerator::SHOW_SYM_LINKS | FileEnumerator::DIRECTORIES; | 109 FileEnumerator::SHOW_SYM_LINKS | FileEnumerator::DIRECTORIES; |
107 FileEnumerator traversal(source_dir, true, traverse_type); | 110 FileEnumerator traversal(source_dir, true, traverse_type); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 DCHECK(info_ != NULL); | 186 DCHECK(info_ != NULL); |
184 DCHECK_NE(0u, length_); | 187 DCHECK_NE(0u, length_); |
185 } | 188 } |
186 | 189 |
187 PermissionRestorer::~PermissionRestorer() { | 190 PermissionRestorer::~PermissionRestorer() { |
188 if (!RestorePermissionInfo(path_, info_, length_)) | 191 if (!RestorePermissionInfo(path_, info_, length_)) |
189 NOTREACHED(); | 192 NOTREACHED(); |
190 } | 193 } |
191 | 194 |
192 } // namespace file_util | 195 } // namespace file_util |
OLD | NEW |