Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1076)

Unified Diff: mojo/data_pipe_utils/data_pipe_file_utils.cc

Issue 1303343007: Created a blocking copy to temporary file function. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Responded to code review Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/data_pipe_utils/data_pipe_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
« no previous file with comments | « no previous file | mojo/data_pipe_utils/data_pipe_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698