Handle errors properly in FileUtilProxy::CreateTemporary.
If creating the temporary file failed, don't try to open it. If we can't open
it for some reason, delete the temporary so the caller can assume strong
exception safety and not have to delete the file on error.
BUG=none
Review URL: https://codereview.chromium.org/183003009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255767 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: b4d3ed61a60f824caf19a92a00bd7f10ea53052c
diff --git a/base/files/file_util_proxy.cc b/base/files/file_util_proxy.cc
index 141e4e1..447552d 100644
--- a/base/files/file_util_proxy.cc
+++ b/base/files/file_util_proxy.cc
@@ -77,7 +77,12 @@
void RunWork(int additional_file_flags) {
// TODO(darin): file_util should have a variant of CreateTemporaryFile
// that returns a FilePath and a PlatformFile.
- base::CreateTemporaryFile(&file_path_);
+ if (!base::CreateTemporaryFile(&file_path_)) {
+ // TODO(davidben): base::CreateTemporaryFile should preserve the error
+ // code.
+ error_ = File::FILE_ERROR_FAILED;
+ return;
+ }
int file_flags =
PLATFORM_FILE_WRITE |
@@ -90,6 +95,10 @@
file_handle_ =
CreatePlatformFile(file_path_, file_flags, NULL,
reinterpret_cast<PlatformFileError*>(&error_));
+ if (error_ != File::FILE_OK) {
+ base::DeleteFile(file_path_, false);
+ file_path_.clear();
+ }
}
void Reply(const FileUtilProxy::CreateTemporaryCallback& callback) {