Chromium Code Reviews| Index: mojo/data_pipe_utils/data_pipe_file_utils.cc |
| diff --git a/mojo/data_pipe_utils/data_pipe_file_utils.cc b/mojo/data_pipe_utils/data_pipe_file_utils.cc |
| index e37c8dfe9aeee9140bb33717c5b55d5066c8f9b3..9cf9ba5000f8dda999495552171dd4533ae59cc6 100644 |
| --- a/mojo/data_pipe_utils/data_pipe_file_utils.cc |
| +++ b/mojo/data_pipe_utils/data_pipe_file_utils.cc |
| @@ -315,18 +315,24 @@ size_t CopyToFileHelper(FILE* fp, const void* buffer, uint32_t num_bytes) { |
| } // namespace |
| -bool BlockingCopyToFile(ScopedDataPipeConsumerHandle source, |
| - const base::FilePath& destination) { |
| - TRACE_EVENT1("data_pipe_utils", "BlockingCopyToFile", "dest", |
| - destination.MaybeAsASCII()); |
| - base::ScopedFILE fp(base::OpenFile(destination, "wb")); |
| +FILE* BlockingCopyToTempFile(ScopedDataPipeConsumerHandle source) { |
| + base::FilePath path; |
| + FILE* fp(CreateAndOpenTemporaryFile(&path)); |
| if (!fp) { |
| - LOG(ERROR) << "OpenFile('" << destination.value() |
| - << "'failed in BlockingCopyToFile"; |
| - return false; |
| + LOG(ERROR) << "CreateAndOpenTemporaryFile failed in" |
| + << "BlockingCopyToTempFile"; |
| + return NULL; |
| } |
| - return BlockingCopyHelper(source.Pass(), |
| - base::Bind(&CopyToFileHelper, fp.get())); |
| + if (unlink(path.value().c_str())) { |
| + LOG(ERROR) << "Failed to unlink temporary file"; |
| + return NULL; |
| + } |
| + if (!BlockingCopyHelper(source.Pass(), |
| + base::Bind(&CopyToFileHelper, fp))) { |
|
Mark Seaborn
2015/09/02 18:46:45
Nit: fix indentation
Sean Klein
2015/09/02 21:49:11
Done.
|
| + LOG(ERROR) << "Could not copy source to temporary file"; |
|
Mark Seaborn
2015/09/02 18:46:45
Nit: this error path doesn't fclose(fp). You coul
Sean Klein
2015/09/02 21:49:11
Using ScopedFILE.
|
| + return NULL; |
| + } |
| + return fp; |
| } |
| void CopyToFile(ScopedDataPipeConsumerHandle source, |