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/file_util.h" | 5 #include "base/file_util.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <psapi.h> | 8 #include <psapi.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } | 206 } |
207 | 207 |
208 bool DirectoryExists(const FilePath& path) { | 208 bool DirectoryExists(const FilePath& path) { |
209 ThreadRestrictions::AssertIOAllowed(); | 209 ThreadRestrictions::AssertIOAllowed(); |
210 DWORD fileattr = GetFileAttributes(path.value().c_str()); | 210 DWORD fileattr = GetFileAttributes(path.value().c_str()); |
211 if (fileattr != INVALID_FILE_ATTRIBUTES) | 211 if (fileattr != INVALID_FILE_ATTRIBUTES) |
212 return (fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0; | 212 return (fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0; |
213 return false; | 213 return false; |
214 } | 214 } |
215 | 215 |
216 } // namespace base | |
217 | |
218 // ----------------------------------------------------------------------------- | |
219 | |
220 namespace file_util { | |
221 | |
222 using base::DirectoryExists; | |
223 using base::FilePath; | |
224 using base::kFileShareAll; | |
225 | |
226 bool GetTempDir(FilePath* path) { | 216 bool GetTempDir(FilePath* path) { |
227 base::ThreadRestrictions::AssertIOAllowed(); | 217 ThreadRestrictions::AssertIOAllowed(); |
228 | 218 |
229 wchar_t temp_path[MAX_PATH + 1]; | 219 wchar_t temp_path[MAX_PATH + 1]; |
230 DWORD path_len = ::GetTempPath(MAX_PATH, temp_path); | 220 DWORD path_len = ::GetTempPath(MAX_PATH, temp_path); |
231 if (path_len >= MAX_PATH || path_len <= 0) | 221 if (path_len >= MAX_PATH || path_len <= 0) |
232 return false; | 222 return false; |
233 // TODO(evanm): the old behavior of this function was to always strip the | 223 // TODO(evanm): the old behavior of this function was to always strip the |
234 // trailing slash. We duplicate this here, but it shouldn't be necessary | 224 // trailing slash. We duplicate this here, but it shouldn't be necessary |
235 // when everyone is using the appropriate FilePath APIs. | 225 // when everyone is using the appropriate FilePath APIs. |
236 *path = FilePath(temp_path).StripTrailingSeparators(); | 226 *path = FilePath(temp_path).StripTrailingSeparators(); |
237 return true; | 227 return true; |
238 } | 228 } |
239 | 229 |
240 bool GetShmemTempDir(FilePath* path, bool executable) { | 230 bool GetShmemTempDir(bool executable, FilePath* path) { |
241 return GetTempDir(path); | 231 return GetTempDir(path); |
242 } | 232 } |
243 | 233 |
| 234 } // namespace base |
| 235 |
| 236 // ----------------------------------------------------------------------------- |
| 237 |
| 238 namespace file_util { |
| 239 |
| 240 using base::DirectoryExists; |
| 241 using base::FilePath; |
| 242 using base::kFileShareAll; |
| 243 |
244 bool CreateTemporaryFile(FilePath* path) { | 244 bool CreateTemporaryFile(FilePath* path) { |
245 base::ThreadRestrictions::AssertIOAllowed(); | 245 base::ThreadRestrictions::AssertIOAllowed(); |
246 | 246 |
247 FilePath temp_file; | 247 FilePath temp_file; |
248 | 248 |
249 if (!GetTempDir(path)) | 249 if (!GetTempDir(path)) |
250 return false; | 250 return false; |
251 | 251 |
252 if (CreateTemporaryFileInDir(*path, &temp_file)) { | 252 if (CreateTemporaryFileInDir(*path, &temp_file)) { |
253 *path = temp_file; | 253 *path = temp_file; |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 // Like Move, this function is not transactional, so we just | 744 // Like Move, this function is not transactional, so we just |
745 // leave the copied bits behind if deleting from_path fails. | 745 // leave the copied bits behind if deleting from_path fails. |
746 // If to_path exists previously then we have already overwritten | 746 // If to_path exists previously then we have already overwritten |
747 // it by now, we don't get better off by deleting the new bits. | 747 // it by now, we don't get better off by deleting the new bits. |
748 } | 748 } |
749 return false; | 749 return false; |
750 } | 750 } |
751 | 751 |
752 } // namespace internal | 752 } // namespace internal |
753 } // namespace base | 753 } // namespace base |
OLD | NEW |