Commit 33894a73 authored by Tomasz Śniatowski's avatar Tomasz Śniatowski Committed by Commit Bot

Use given trace file directly if the temp file doesn't work

Fall back to the old behavior of just writing to a trace file directly
if we're unable to open a temporary file in the same directory. This can
happen in some configurations on restrictive Android systems for
example, where the browser may only be able to write to the actual file
specified in --trace-startup-file, and not to any nearby path.

Bug: 1082916
Change-Id: I3c1275b4c70cc8edb6e50adc321ba412c6226de8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346352Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
Commit-Queue: Tomasz Śniatowski <tsniatowski@vewd.com>
Cr-Commit-Position: refs/heads/master@{#796735}
parent 39c1e76f
...@@ -90,14 +90,20 @@ class FileTraceDataEndpoint : public TracingController::TraceDataEndpoint { ...@@ -90,14 +90,20 @@ class FileTraceDataEndpoint : public TracingController::TraceDataEndpoint {
// The temporary trace file is produced in the same folder since paths must // The temporary trace file is produced in the same folder since paths must
// be on the same volume. // be on the same volume.
file_ = FileToFILE(CreateAndOpenTemporaryFileInDir(file_path_.DirName(), base::File temp_file = CreateAndOpenTemporaryFileInDir(file_path_.DirName(),
&pending_file_path_), &pending_file_path_);
"w"); if (temp_file.IsValid()) {
if (file_ == nullptr) { file_ = FileToFILE(std::move(temp_file), "w");
LOG(ERROR) << "Failed to open " << file_path_.value(); } else {
return false; LOG(WARNING) << "Unable to use temporary file " << pending_file_path_
<< ": "
<< base::File::ErrorToString(temp_file.error_details());
pending_file_path_.clear();
file_ = base::OpenFile(file_path_, "w");
LOG_IF(ERROR, file_ == nullptr)
<< "Failed to open " << file_path_.value();
} }
return true; return file_ != nullptr;
} }
void CloseOnBlockingThread() { void CloseOnBlockingThread() {
...@@ -106,6 +112,7 @@ class FileTraceDataEndpoint : public TracingController::TraceDataEndpoint { ...@@ -106,6 +112,7 @@ class FileTraceDataEndpoint : public TracingController::TraceDataEndpoint {
file_ = nullptr; file_ = nullptr;
} }
if (!pending_file_path_.empty()) {
base::File::Error error; base::File::Error error;
if (!base::ReplaceFile(pending_file_path_, file_path_, &error)) { if (!base::ReplaceFile(pending_file_path_, file_path_, &error)) {
LOG(ERROR) << "Cannot replace file '" << file_path_ LOG(ERROR) << "Cannot replace file '" << file_path_
...@@ -113,6 +120,7 @@ class FileTraceDataEndpoint : public TracingController::TraceDataEndpoint { ...@@ -113,6 +120,7 @@ class FileTraceDataEndpoint : public TracingController::TraceDataEndpoint {
base::DeleteFile(pending_file_path_); base::DeleteFile(pending_file_path_);
return; return;
} }
}
GetUIThreadTaskRunner({})->PostTask( GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, FROM_HERE,
......
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