Skip to content

Commit

Permalink
log attachment file size
Browse files Browse the repository at this point in the history
To check whether dump file size is too big to be uploaded.

Bug: b/130366217
Test: build and run; file feedback and check logcat
Change-Id: I12ddd67a48255319b31725b36f9c28285465f233
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1625899
Reviewed-by: Yuchen Liu <yucliu@chromium.org>
Commit-Queue: Yi Fan <yfa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686233}
  • Loading branch information
Yi Fan authored and Commit Bot committed Aug 12, 2019
1 parent 109c27a commit dbe50ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 8 additions & 0 deletions chromecast/crash/cast_crashdump_uploader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <sys/stat.h>

#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
// TODO(slan): Find a replacement for LibcurlWrapper in Chromium to remove the
// breakpad dependency.
Expand Down Expand Up @@ -51,6 +53,12 @@ CastCrashdumpUploader::~CastCrashdumpUploader() {

bool CastCrashdumpUploader::AddAttachment(const std::string& label,
const std::string& filename) {
int64_t file_size = 0;
if (!base::GetFileSize(base::FilePath(filename), &file_size)) {
LOG(WARNING) << "file size of " << filename << " not readable";
return false;
}
LOG(INFO) << "file size of " << filename << ": " << file_size;
attachments_[label] = filename;
return true;
}
Expand Down
6 changes: 1 addition & 5 deletions chromecast/crash/cast_crashdump_uploader_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ TEST(CastCrashdumpUploaderTest, UploadFailsWithInvalidAttachment) {
// Create a temporary file.
ScopedTempFile minidump;

EXPECT_CALL(*m, Init()).Times(1).WillOnce(Return(true));
EXPECT_CALL(*m, AddFile(minidump.path().value(), _)).WillOnce(Return(true));

CastCrashdumpData data;
data.product = "foobar";
data.version = "1.0";
Expand All @@ -152,8 +149,7 @@ TEST(CastCrashdumpUploaderTest, UploadFailsWithInvalidAttachment) {
CastCrashdumpUploader uploader(data, std::move(m));

// Add a file that does not exist as an attachment.
uploader.AddAttachment("label", "/path/does/not/exist");
ASSERT_FALSE(uploader.Upload(nullptr));
ASSERT_FALSE(uploader.AddAttachment("label", "/path/does/not/exist"));
}

TEST(CastCrashdumpUploaderTest, UploadSucceedsWithValidAttachment) {
Expand Down

0 comments on commit dbe50ca

Please sign in to comment.