Commit b4d3ed61 authored by davidben@chromium.org's avatar davidben@chromium.org

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
parent 34c7b3e5
...@@ -77,7 +77,12 @@ class CreateTemporaryHelper { ...@@ -77,7 +77,12 @@ class CreateTemporaryHelper {
void RunWork(int additional_file_flags) { void RunWork(int additional_file_flags) {
// TODO(darin): file_util should have a variant of CreateTemporaryFile // TODO(darin): file_util should have a variant of CreateTemporaryFile
// that returns a FilePath and a PlatformFile. // 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 = int file_flags =
PLATFORM_FILE_WRITE | PLATFORM_FILE_WRITE |
...@@ -90,6 +95,10 @@ class CreateTemporaryHelper { ...@@ -90,6 +95,10 @@ class CreateTemporaryHelper {
file_handle_ = file_handle_ =
CreatePlatformFile(file_path_, file_flags, NULL, CreatePlatformFile(file_path_, file_flags, NULL,
reinterpret_cast<PlatformFileError*>(&error_)); reinterpret_cast<PlatformFileError*>(&error_));
if (error_ != File::FILE_OK) {
base::DeleteFile(file_path_, false);
file_path_.clear();
}
} }
void Reply(const FileUtilProxy::CreateTemporaryCallback& callback) { void Reply(const FileUtilProxy::CreateTemporaryCallback& callback) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment