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 #include <windows.h> | 7 #include <windows.h> |
8 #include <io.h> | 8 #include <io.h> |
9 #include <psapi.h> | 9 #include <psapi.h> |
10 #include <shellapi.h> | 10 #include <shellapi.h> |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 temp_name = dir.Append(ASCIIToUTF16(base::GenerateGUID()) + L".tmp"); | 357 temp_name = dir.Append(ASCIIToUTF16(base::GenerateGUID()) + L".tmp"); |
358 File file(temp_name, | 358 File file(temp_name, |
359 File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE); | 359 File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE); |
360 if (file.IsValid()) { | 360 if (file.IsValid()) { |
361 file.Close(); | 361 file.Close(); |
362 create_file_success = true; | 362 create_file_success = true; |
363 break; | 363 break; |
364 } | 364 } |
365 } | 365 } |
366 | 366 |
367 // Exist early if we can't create an unique name. | |
368 if (!create_file_success) { | 367 if (!create_file_success) { |
369 DPLOG(WARNING) << "Failed to get temporary file name in " | 368 DPLOG(WARNING) << "Failed to get temporary file name in " |
370 << UTF16ToUTF8(dir.value()); | 369 << UTF16ToUTF8(dir.value()); |
371 return false; | 370 return false; |
372 } | 371 } |
373 | 372 |
374 wchar_t long_temp_name[MAX_PATH + 1]; | 373 wchar_t long_temp_name[MAX_PATH + 1]; |
375 DWORD long_name_len = | 374 DWORD long_name_len = |
376 GetLongPathName(temp_name.value().c_str(), long_temp_name, MAX_PATH); | 375 GetLongPathName(temp_name.value().c_str(), long_temp_name, MAX_PATH); |
377 if (long_name_len > MAX_PATH || long_name_len == 0) { | 376 if (long_name_len > MAX_PATH || long_name_len == 0) { |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 // Like Move, this function is not transactional, so we just | 865 // Like Move, this function is not transactional, so we just |
867 // leave the copied bits behind if deleting from_path fails. | 866 // leave the copied bits behind if deleting from_path fails. |
868 // If to_path exists previously then we have already overwritten | 867 // If to_path exists previously then we have already overwritten |
869 // it by now, we don't get better off by deleting the new bits. | 868 // it by now, we don't get better off by deleting the new bits. |
870 } | 869 } |
871 return false; | 870 return false; |
872 } | 871 } |
873 | 872 |
874 } // namespace internal | 873 } // namespace internal |
875 } // namespace base | 874 } // namespace base |
OLD | NEW |