Chromium Code Reviews| Index: base/files/file_util_win.cc |
| diff --git a/base/files/file_util_win.cc b/base/files/file_util_win.cc |
| index 65dc5ce1e2fe7495624cc6d8c16b954395eb11ac..f057d14037367bd56d7570908187e93e99a96132 100644 |
| --- a/base/files/file_util_win.cc |
| +++ b/base/files/file_util_win.cc |
| @@ -20,6 +20,7 @@ |
| #include "base/files/file_enumerator.h" |
| #include "base/files/file_path.h" |
| +#include "base/guid.h" |
| #include "base/logging.h" |
| #include "base/macros.h" |
| #include "base/metrics/histogram.h" |
| @@ -340,19 +341,26 @@ FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, FilePath* path) { |
| bool CreateTemporaryFileInDir(const FilePath& dir, FilePath* temp_file) { |
| ThreadRestrictions::AssertIOAllowed(); |
| - wchar_t temp_name[MAX_PATH + 1]; |
| - |
| - if (!GetTempFileName(dir.value().c_str(), L"", 0, temp_name)) { |
| + FilePath::StringType temp_file_name = |
|
grt (UTC plus 2)
2017/04/06 10:35:02
please leave a comment explaining why GetTempFileN
chengx
2017/04/06 17:46:01
Comments added.
|
| + ASCIIToUTF16(base::GenerateGUID() + ".tmp"); |
| + FilePath temp_name = dir.Append(temp_file_name); |
| + File file(::CreateFile(temp_name.value().c_str(), |
|
grt (UTC plus 2)
2017/04/06 10:35:02
can you not use the (const FilePath& path, uint32_
chengx
2017/04/06 17:46:01
Done. Changed to the (const FilePath& path, uint32
|
| + GENERIC_READ | GENERIC_WRITE, |
| + FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, |
| + CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr)); |
| + if (!file.IsValid()) { |
| DPLOG(WARNING) << "Failed to get temporary file name in " |
| << UTF16ToUTF8(dir.value()); |
| return false; |
| } |
| + file.Close(); |
| wchar_t long_temp_name[MAX_PATH + 1]; |
| - DWORD long_name_len = GetLongPathName(temp_name, long_temp_name, MAX_PATH); |
| + DWORD long_name_len = |
| + GetLongPathName(temp_name.value().c_str(), long_temp_name, MAX_PATH); |
| if (long_name_len > MAX_PATH || long_name_len == 0) { |
| // GetLongPathName() failed, but we still have a temporary file. |
| - *temp_file = FilePath(temp_name); |
| + *temp_file = temp_name; |
| return true; |
| } |