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..7a8f87b99af178c49a561ef5071d5269e0dfd64e 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")); |
+base::ScopedFILE BlockingCopyToTempFile(ScopedDataPipeConsumerHandle source) { |
+ base::FilePath path; |
+ base::ScopedFILE fp(CreateAndOpenTemporaryFile(&path)); |
if (!fp) { |
- LOG(ERROR) << "OpenFile('" << destination.value() |
- << "'failed in BlockingCopyToFile"; |
- return false; |
+ LOG(ERROR) << "CreateAndOpenTemporaryFile failed in" |
+ << "BlockingCopyToTempFile"; |
+ return NULL; |
jamesr
2015/09/02 23:29:31
s/NULL/nullptr/. Only use NULL in code that has t
Sean Klein
2015/09/02 23:35:35
Whoops! Sorry, a bit new to C++, and old habits di
|
} |
- 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.get()))) { |
+ LOG(ERROR) << "Could not copy source to temporary file"; |
+ return NULL; |
jamesr
2015/09/02 23:29:31
ditto
Sean Klein
2015/09/02 23:35:35
Done.
|
+ } |
+ return fp; |
} |
void CopyToFile(ScopedDataPipeConsumerHandle source, |