update_engine: Fix leaking unit tests
Some of the unit tests have been leaking temp files because they don't
properly unlink them. In this CL, we did some rearrangement of the
ScopedTempFile class and moved it into the utils.h (instead of testing
only location) so it can be used everywhere and more efficiently. Also
added functionality to open an file descriptor too so users don't have
to keep a different object for the file descriptor.
BUG=b:162766400
TEST=cros_workon_make --board reef --test; Then looked at the
/build/reef/tmp directory and no files were leaked.
Change-Id: Id64a2923d30f27628120497fdefe16bf65fa3fb0
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2500772
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
Commit-Queue: Amin Hassani <ahassani@chromium.org>
diff --git a/payload_generator/ab_generator_unittest.cc b/payload_generator/ab_generator_unittest.cc
index 7a95284..84eeb77 100644
--- a/payload_generator/ab_generator_unittest.cc
+++ b/payload_generator/ab_generator_unittest.cc
@@ -70,8 +70,7 @@
part_data.push_back(dis(gen));
}
ASSERT_EQ(part_size, part_data.size());
- test_utils::ScopedTempFile part_file(
- "SplitReplaceOrReplaceXzTest_part.XXXXXX");
+ ScopedTempFile part_file("SplitReplaceOrReplaceXzTest_part.XXXXXX");
ASSERT_TRUE(test_utils::WriteFileVector(part_file.path(), part_data));
// Create original operation and blob data.
@@ -107,8 +106,7 @@
aop.name = "SplitTestOp";
// Create the data file.
- test_utils::ScopedTempFile data_file(
- "SplitReplaceOrReplaceXzTest_data.XXXXXX");
+ ScopedTempFile data_file("SplitReplaceOrReplaceXzTest_data.XXXXXX");
EXPECT_TRUE(test_utils::WriteFileVector(data_file.path(), op_blob));
int data_fd = open(data_file.path().c_str(), O_RDWR, 000);
EXPECT_GE(data_fd, 0);
@@ -220,8 +218,7 @@
part_data.push_back(dis(gen));
}
ASSERT_EQ(part_size, part_data.size());
- test_utils::ScopedTempFile part_file(
- "MergeReplaceOrReplaceXzTest_part.XXXXXX");
+ ScopedTempFile part_file("MergeReplaceOrReplaceXzTest_part.XXXXXX");
ASSERT_TRUE(test_utils::WriteFileVector(part_file.path(), part_data));
// Create original operations and blob data.
@@ -271,8 +268,7 @@
aops.push_back(second_aop);
// Create the data file.
- test_utils::ScopedTempFile data_file(
- "MergeReplaceOrReplaceXzTest_data.XXXXXX");
+ ScopedTempFile data_file("MergeReplaceOrReplaceXzTest_data.XXXXXX");
EXPECT_TRUE(test_utils::WriteFileVector(data_file.path(), blob_data));
int data_fd = open(data_file.path().c_str(), O_RDWR, 000);
EXPECT_GE(data_fd, 0);
@@ -561,7 +557,7 @@
second_aop.op = second_op;
aops.push_back(second_aop);
- test_utils::ScopedTempFile src_part_file("AddSourceHashTest_src_part.XXXXXX");
+ ScopedTempFile src_part_file("AddSourceHashTest_src_part.XXXXXX");
brillo::Blob src_data(kBlockSize);
test_utils::FillWithData(&src_data);
ASSERT_TRUE(test_utils::WriteFileVector(src_part_file.path(), src_data));
diff --git a/payload_generator/blob_file_writer_unittest.cc b/payload_generator/blob_file_writer_unittest.cc
index 487bc73..f4dcafb 100644
--- a/payload_generator/blob_file_writer_unittest.cc
+++ b/payload_generator/blob_file_writer_unittest.cc
@@ -31,24 +31,21 @@
class BlobFileWriterTest : public ::testing::Test {};
TEST(BlobFileWriterTest, SimpleTest) {
- string blob_path;
- int blob_fd;
- EXPECT_TRUE(
- utils::MakeTempFile("BlobFileWriterTest.XXXXXX", &blob_path, &blob_fd));
+ ScopedTempFile blob_file("BlobFileWriterTest.XXXXXX", true);
off_t blob_file_size = 0;
- BlobFileWriter blob_file(blob_fd, &blob_file_size);
+ BlobFileWriter blob_file_writer(blob_file.fd(), &blob_file_size);
- off_t blob_size = 1024;
- brillo::Blob blob(blob_size);
+ const off_t kBlobSize = 1024;
+ brillo::Blob blob(kBlobSize);
FillWithData(&blob);
- EXPECT_EQ(0, blob_file.StoreBlob(blob));
- EXPECT_EQ(blob_size, blob_file.StoreBlob(blob));
+ EXPECT_EQ(0, blob_file_writer.StoreBlob(blob));
+ EXPECT_EQ(kBlobSize, blob_file_writer.StoreBlob(blob));
- brillo::Blob stored_blob(blob_size);
+ brillo::Blob stored_blob(kBlobSize);
ssize_t bytes_read;
- ASSERT_TRUE(
- utils::PReadAll(blob_fd, stored_blob.data(), blob_size, 0, &bytes_read));
- EXPECT_EQ(bytes_read, blob_size);
+ ASSERT_TRUE(utils::PReadAll(
+ blob_file.fd(), stored_blob.data(), kBlobSize, 0, &bytes_read));
+ EXPECT_EQ(bytes_read, kBlobSize);
EXPECT_EQ(blob, stored_blob);
}
diff --git a/payload_generator/block_mapping_unittest.cc b/payload_generator/block_mapping_unittest.cc
index 9b9b4f1..017548a 100644
--- a/payload_generator/block_mapping_unittest.cc
+++ b/payload_generator/block_mapping_unittest.cc
@@ -36,8 +36,8 @@
class BlockMappingTest : public ::testing::Test {
protected:
// Old new partition files used in testing.
- test_utils::ScopedTempFile old_part_{"BlockMappingTest_old.XXXXXX"};
- test_utils::ScopedTempFile new_part_{"BlockMappingTest_new.XXXXXX"};
+ ScopedTempFile old_part_{"BlockMappingTest_old.XXXXXX"};
+ ScopedTempFile new_part_{"BlockMappingTest_new.XXXXXX"};
size_t block_size_{1024};
BlockMapping bm_{block_size_}; // BlockMapping under test.
diff --git a/payload_generator/boot_img_filesystem_unittest.cc b/payload_generator/boot_img_filesystem_unittest.cc
index 0b115e0..7805156 100644
--- a/payload_generator/boot_img_filesystem_unittest.cc
+++ b/payload_generator/boot_img_filesystem_unittest.cc
@@ -63,7 +63,7 @@
return boot_img;
}
- test_utils::ScopedTempFile boot_file_;
+ ScopedTempFile boot_file_;
};
TEST_F(BootImgFilesystemTest, SimpleTest) {
diff --git a/payload_generator/delta_diff_generator.cc b/payload_generator/delta_diff_generator.cc
index c2b35ee..ff8b0da 100644
--- a/payload_generator/delta_diff_generator.cc
+++ b/payload_generator/delta_diff_generator.cc
@@ -119,18 +119,10 @@
PayloadFile payload;
TEST_AND_RETURN_FALSE(payload.Init(config));
- const string kTempFileTemplate("CrAU_temp_data.XXXXXX");
- string temp_file_path;
- int data_file_fd;
- TEST_AND_RETURN_FALSE(
- utils::MakeTempFile(kTempFileTemplate, &temp_file_path, &data_file_fd));
- ScopedPathUnlinker temp_file_unlinker(temp_file_path);
- TEST_AND_RETURN_FALSE(data_file_fd >= 0);
-
+ ScopedTempFile data_file("CrAU_temp_data.XXXXXX", true);
{
off_t data_file_size = 0;
- ScopedFdCloser data_file_fd_closer(&data_file_fd);
- BlobFileWriter blob_file(data_file_fd, &data_file_size);
+ BlobFileWriter blob_file(data_file.fd(), &data_file_size);
if (config.is_delta) {
TEST_AND_RETURN_FALSE(config.source.partitions.size() ==
config.target.partitions.size());
@@ -190,11 +182,12 @@
std::move(all_merge_sequences[i])));
}
}
+ data_file.CloseFd();
LOG(INFO) << "Writing payload file...";
// Write payload file to disk.
TEST_AND_RETURN_FALSE(payload.WritePayload(
- output_path, temp_file_path, private_key_path, metadata_size));
+ output_path, data_file.path(), private_key_path, metadata_size));
LOG(INFO) << "All done. Successfully created delta file with "
<< "metadata size = " << *metadata_size;
diff --git a/payload_generator/delta_diff_utils.cc b/payload_generator/delta_diff_utils.cc
index 220c7ae..3c025e1 100644
--- a/payload_generator/delta_diff_utils.cc
+++ b/payload_generator/delta_diff_utils.cc
@@ -822,17 +822,13 @@
// Only Puffdiff if both files have at least one deflate left.
if (!src_deflates.empty() && !dst_deflates.empty()) {
brillo::Blob puffdiff_delta;
- string temp_file_path;
- TEST_AND_RETURN_FALSE(utils::MakeTempFile(
- "puffdiff-delta.XXXXXX", &temp_file_path, nullptr));
- ScopedPathUnlinker temp_file_unlinker(temp_file_path);
-
+ ScopedTempFile temp_file("puffdiff-delta.XXXXXX");
// Perform PuffDiff operation.
TEST_AND_RETURN_FALSE(puffin::PuffDiff(old_data,
new_data,
src_deflates,
dst_deflates,
- temp_file_path,
+ temp_file.path(),
&puffdiff_delta));
TEST_AND_RETURN_FALSE(puffdiff_delta.size() > 0);
if (IsDiffOperationBetter(operation,
diff --git a/payload_generator/delta_diff_utils_unittest.cc b/payload_generator/delta_diff_utils_unittest.cc
index 0857f9c..f2db1bd 100644
--- a/payload_generator/delta_diff_utils_unittest.cc
+++ b/payload_generator/delta_diff_utils_unittest.cc
@@ -69,13 +69,12 @@
// Create a fake filesystem of the given |size| and initialize the partition
// holding it in the PartitionConfig |part|.
void CreatePartition(PartitionConfig* part,
- const string& pattern,
+ ScopedTempFile* part_file,
uint64_t block_size,
off_t size) {
- int fd = -1;
- ASSERT_TRUE(utils::MakeTempFile(pattern.c_str(), &part->path, &fd));
- ASSERT_EQ(0, ftruncate(fd, size));
- ASSERT_EQ(0, close(fd));
+ part->path = part_file->path();
+ ASSERT_EQ(0, ftruncate(part_file->fd(), size));
+ part_file->CloseFd();
part->fs_interface.reset(new FakeFilesystem(block_size, size / block_size));
part->size = size;
}
@@ -112,30 +111,20 @@
void SetUp() override {
CreatePartition(&old_part_,
- "DeltaDiffUtilsTest-old_part-XXXXXX",
+ &old_part_file_,
block_size_,
block_size_ * kDefaultBlockCount);
CreatePartition(&new_part_,
- "DeltaDiffUtilsTest-old_part-XXXXXX",
+ &new_part_file_,
block_size_,
block_size_ * kDefaultBlockCount);
- ASSERT_TRUE(utils::MakeTempFile(
- "DeltaDiffUtilsTest-blob-XXXXXX", &blob_path_, &blob_fd_));
- }
-
- void TearDown() override {
- unlink(old_part_.path.c_str());
- unlink(new_part_.path.c_str());
- if (blob_fd_ != -1)
- close(blob_fd_);
- unlink(blob_path_.c_str());
}
// Helper function to call DeltaMovedAndZeroBlocks() using this class' data
// members. This simply avoids repeating all the arguments that never change.
bool RunDeltaMovedAndZeroBlocks(ssize_t chunk_blocks,
uint32_t minor_version) {
- BlobFileWriter blob_file(blob_fd_, &blob_size_);
+ BlobFileWriter blob_file(tmp_blob_file_.fd(), &blob_size_);
PayloadVersion version(kBrilloMajorPayloadVersion, minor_version);
ExtentRanges old_zero_blocks;
return diff_utils::DeltaMovedAndZeroBlocks(&aops_,
@@ -155,10 +144,11 @@
// with
PartitionConfig old_part_{"part"};
PartitionConfig new_part_{"part"};
+ ScopedTempFile old_part_file_{"DeltaDiffUtilsTest-old_part-XXXXXX", true};
+ ScopedTempFile new_part_file_{"DeltaDiffUtilsTest-new_part-XXXXXX", true};
// The file holding the output blob from the various diff utils functions.
- string blob_path_;
- int blob_fd_{-1};
+ ScopedTempFile tmp_blob_file_{"DeltaDiffUtilsTest-blob-XXXXXX", true};
off_t blob_size_{0};
size_t block_size_{kBlockSize};
@@ -173,7 +163,7 @@
new_part_.verity.hash_tree_extent = ExtentForRange(20, 30);
new_part_.verity.fec_extent = ExtentForRange(40, 50);
- BlobFileWriter blob_file(blob_fd_, &blob_size_);
+ BlobFileWriter blob_file(tmp_blob_file_.fd(), &blob_size_);
EXPECT_TRUE(diff_utils::DeltaReadPartition(
&aops_,
old_part_,
diff --git a/payload_generator/ext2_filesystem_unittest.cc b/payload_generator/ext2_filesystem_unittest.cc
index 54600e9..88e1538 100644
--- a/payload_generator/ext2_filesystem_unittest.cc
+++ b/payload_generator/ext2_filesystem_unittest.cc
@@ -62,7 +62,7 @@
class Ext2FilesystemTest : public ::testing::Test {};
TEST_F(Ext2FilesystemTest, InvalidFilesystem) {
- test_utils::ScopedTempFile fs_filename_{"Ext2FilesystemTest-XXXXXX"};
+ ScopedTempFile fs_filename_{"Ext2FilesystemTest-XXXXXX"};
ASSERT_EQ(0, truncate(fs_filename_.path().c_str(), kDefaultFilesystemSize));
unique_ptr<Ext2Filesystem> fs =
Ext2Filesystem::CreateFromFile(fs_filename_.path());
diff --git a/payload_generator/full_update_generator_unittest.cc b/payload_generator/full_update_generator_unittest.cc
index 5f39e8b..d3b3491 100644
--- a/payload_generator/full_update_generator_unittest.cc
+++ b/payload_generator/full_update_generator_unittest.cc
@@ -41,11 +41,9 @@
config_.block_size = 4096;
new_part_conf.path = part_file_.path();
- EXPECT_TRUE(utils::MakeTempFile(
- "FullUpdateTest_blobs.XXXXXX", &out_blobs_path_, &out_blobs_fd_));
- blob_file_.reset(new BlobFileWriter(out_blobs_fd_, &out_blobs_length_));
- out_blobs_unlinker_.reset(new ScopedPathUnlinker(out_blobs_path_));
+ blob_file_writer_.reset(
+ new BlobFileWriter(blob_file_.fd(), &out_blobs_length_));
}
PayloadGenerationConfig config_;
@@ -54,14 +52,11 @@
vector<AnnotatedOperation> aops;
// Output file holding the payload blobs.
- string out_blobs_path_;
- int out_blobs_fd_{-1};
off_t out_blobs_length_{0};
- ScopedFdCloser out_blobs_fd_closer_{&out_blobs_fd_};
- test_utils::ScopedTempFile part_file_{"FullUpdateTest_partition.XXXXXX"};
+ ScopedTempFile part_file_{"FullUpdateTest_partition.XXXXXX"};
- std::unique_ptr<BlobFileWriter> blob_file_;
- std::unique_ptr<ScopedPathUnlinker> out_blobs_unlinker_;
+ ScopedTempFile blob_file_{"FullUpdateTest_blobs.XXXXXX", true};
+ std::unique_ptr<BlobFileWriter> blob_file_writer_;
// FullUpdateGenerator under test.
FullUpdateGenerator generator_;
@@ -77,7 +72,7 @@
EXPECT_TRUE(generator_.GenerateOperations(config_,
new_part_conf, // this is ignored
new_part_conf,
- blob_file_.get(),
+ blob_file_writer_.get(),
&aops));
int64_t new_part_chunks = new_part_conf.size / config_.hard_chunk_size;
EXPECT_EQ(new_part_chunks, static_cast<int64_t>(aops.size()));
@@ -108,7 +103,7 @@
EXPECT_TRUE(generator_.GenerateOperations(config_,
new_part_conf, // this is ignored
new_part_conf,
- blob_file_.get(),
+ blob_file_writer_.get(),
&aops));
// new_part has one chunk and a half.
EXPECT_EQ(2U, aops.size());
@@ -129,7 +124,7 @@
EXPECT_TRUE(generator_.GenerateOperations(config_,
new_part_conf, // this is ignored
new_part_conf,
- blob_file_.get(),
+ blob_file_writer_.get(),
&aops));
// new_part has less than one chunk.
diff --git a/payload_generator/mapfile_filesystem_unittest.cc b/payload_generator/mapfile_filesystem_unittest.cc
index 36ae3bf..57b672b 100644
--- a/payload_generator/mapfile_filesystem_unittest.cc
+++ b/payload_generator/mapfile_filesystem_unittest.cc
@@ -55,8 +55,8 @@
class MapfileFilesystemTest : public ::testing::Test {
protected:
- test_utils::ScopedTempFile temp_file_{"mapfile_file.XXXXXX"};
- test_utils::ScopedTempFile temp_mapfile_{"mapfile_mapfile.XXXXXX"};
+ ScopedTempFile temp_file_{"mapfile_file.XXXXXX"};
+ ScopedTempFile temp_mapfile_{"mapfile_mapfile.XXXXXX"};
};
TEST_F(MapfileFilesystemTest, EmptyFilesystem) {
diff --git a/payload_generator/payload_file.cc b/payload_generator/payload_file.cc
index 2688e9a..74423d1 100644
--- a/payload_generator/payload_file.cc
+++ b/payload_generator/payload_file.cc
@@ -103,11 +103,9 @@
const string& private_key_path,
uint64_t* metadata_size_out) {
// Reorder the data blobs with the manifest_.
- string ordered_blobs_path;
- TEST_AND_RETURN_FALSE(utils::MakeTempFile(
- "CrAU_temp_data.ordered.XXXXXX", &ordered_blobs_path, nullptr));
- ScopedPathUnlinker ordered_blobs_unlinker(ordered_blobs_path);
- TEST_AND_RETURN_FALSE(ReorderDataBlobs(data_blobs_path, ordered_blobs_path));
+ ScopedTempFile ordered_blobs_file("CrAU_temp_data.ordered.XXXXXX");
+ TEST_AND_RETURN_FALSE(
+ ReorderDataBlobs(data_blobs_path, ordered_blobs_file.path()));
// Check that install op blobs are in order.
uint64_t next_blob_offset = 0;
@@ -231,7 +229,7 @@
// Append the data blobs.
LOG(INFO) << "Writing final delta file data blobs...";
- int blobs_fd = open(ordered_blobs_path.c_str(), O_RDONLY, 0);
+ int blobs_fd = open(ordered_blobs_file.path().c_str(), O_RDONLY, 0);
ScopedFdCloser blobs_fd_closer(&blobs_fd);
TEST_AND_RETURN_FALSE(blobs_fd >= 0);
for (;;) {
diff --git a/payload_generator/payload_file_unittest.cc b/payload_generator/payload_file_unittest.cc
index 45faebb9..1fd36f5 100644
--- a/payload_generator/payload_file_unittest.cc
+++ b/payload_generator/payload_file_unittest.cc
@@ -36,7 +36,7 @@
};
TEST_F(PayloadFileTest, ReorderBlobsTest) {
- test_utils::ScopedTempFile orig_blobs("ReorderBlobsTest.orig.XXXXXX");
+ ScopedTempFile orig_blobs("ReorderBlobsTest.orig.XXXXXX");
// The operations have three blob and one gap (the whitespace):
// Rootfs operation 1: [8, 3] bcd
@@ -45,7 +45,7 @@
string orig_data = "kernel abcd";
EXPECT_TRUE(test_utils::WriteFileString(orig_blobs.path(), orig_data));
- test_utils::ScopedTempFile new_blobs("ReorderBlobsTest.new.XXXXXX");
+ ScopedTempFile new_blobs("ReorderBlobsTest.new.XXXXXX");
payload_.part_vec_.resize(2);
diff --git a/payload_generator/payload_generation_config_android_unittest.cc b/payload_generator/payload_generation_config_android_unittest.cc
index 44eaf55..e87b034 100644
--- a/payload_generator/payload_generation_config_android_unittest.cc
+++ b/payload_generator/payload_generation_config_android_unittest.cc
@@ -138,8 +138,7 @@
}
ImageConfig image_config_;
- test_utils::ScopedTempFile temp_file_{
- "PayloadGenerationConfigAndroidTest.XXXXXX"};
+ ScopedTempFile temp_file_{"PayloadGenerationConfigAndroidTest.XXXXXX"};
};
TEST_F(PayloadGenerationConfigAndroidTest, LoadVerityConfigSimpleTest) {
diff --git a/payload_generator/payload_properties_unittest.cc b/payload_generator/payload_properties_unittest.cc
index 19bc2f8..ed936ff 100644
--- a/payload_generator/payload_properties_unittest.cc
+++ b/payload_generator/payload_properties_unittest.cc
@@ -40,7 +40,6 @@
#include "update_engine/payload_generator/payload_file.h"
#include "update_engine/payload_generator/payload_generation_config.h"
-using chromeos_update_engine::test_utils::ScopedTempFile;
using std::string;
using std::unique_ptr;
using std::vector;
@@ -60,14 +59,6 @@
PayloadFile payload;
EXPECT_TRUE(payload.Init(config));
- const string kTempFileTemplate = "temp_data.XXXXXX";
- int data_file_fd;
- string temp_file_path;
- EXPECT_TRUE(
- utils::MakeTempFile(kTempFileTemplate, &temp_file_path, &data_file_fd));
- ScopedPathUnlinker temp_file_unlinker(temp_file_path);
- EXPECT_LE(0, data_file_fd);
-
const auto SetupPartitionConfig =
[](PartitionConfig* config, const string& path, size_t size) {
config->path = path;
@@ -77,8 +68,8 @@
string zeros(size, '\0');
EXPECT_TRUE(utils::WriteFile(path, zeros.c_str(), zeros.size()));
};
- ScopedTempFile old_part_file;
- ScopedTempFile new_part_file;
+ ScopedTempFile old_part_file("old_part.XXXXXX");
+ ScopedTempFile new_part_file("new_part.XXXXXX");
PartitionConfig old_part(kPartitionNameRoot);
PartitionConfig new_part(kPartitionNameRoot);
SetupPartitionConfig(&old_part, old_part_file.path(), 0);
@@ -91,7 +82,8 @@
vector<AnnotatedOperation> aops;
off_t data_file_size = 0;
- BlobFileWriter blob_file_writer(data_file_fd, &data_file_size);
+ ScopedTempFile data_file("temp_data.XXXXXX", true);
+ BlobFileWriter blob_file_writer(data_file.fd(), &data_file_size);
// Generate the operations using the strategy we selected above.
EXPECT_TRUE(strategy->GenerateOperations(
config, old_part, new_part, &blob_file_writer, &aops));
@@ -100,10 +92,10 @@
uint64_t metadata_size;
EXPECT_TRUE(payload.WritePayload(
- payload_file.path(), temp_file_path, "", &metadata_size));
+ payload_file_.path(), data_file.path(), "", &metadata_size));
}
- ScopedTempFile payload_file;
+ ScopedTempFile payload_file_{"payload_file.XXXXXX"};
};
// Validate the hash of file exists within the output.
@@ -119,7 +111,7 @@
"}";
string json;
EXPECT_TRUE(
- PayloadProperties(payload_file.path()).GetPropertiesAsJson(&json));
+ PayloadProperties(payload_file_.path()).GetPropertiesAsJson(&json));
EXPECT_EQ(kJsonProperties, json) << "JSON contents:\n" << json;
}
@@ -131,7 +123,7 @@
"METADATA_HASH=aEKYyzJt2E8Gz8fzB+gmekN5mriotZCSq6R+kDfdeV4=\n"
"METADATA_SIZE=165\n";
string key_value;
- EXPECT_TRUE(PayloadProperties{payload_file.path()}.GetPropertiesAsKeyValue(
+ EXPECT_TRUE(PayloadProperties{payload_file_.path()}.GetPropertiesAsKeyValue(
&key_value));
EXPECT_EQ(kKeyValueProperties, key_value) << "Key Value contents:\n"
<< key_value;
diff --git a/payload_generator/payload_signer_unittest.cc b/payload_generator/payload_signer_unittest.cc
index fe62997..2a0b394 100644
--- a/payload_generator/payload_signer_unittest.cc
+++ b/payload_generator/payload_signer_unittest.cc
@@ -167,7 +167,7 @@
}
TEST_F(PayloadSignerTest, SkipMetadataSignatureTest) {
- test_utils::ScopedTempFile payload_file("payload.XXXXXX");
+ ScopedTempFile payload_file("payload.XXXXXX");
PayloadGenerationConfig config;
config.version.major = kBrilloMajorPayloadVersion;
PayloadFile payload;
@@ -194,7 +194,7 @@
}
TEST_F(PayloadSignerTest, VerifySignedPayloadTest) {
- test_utils::ScopedTempFile payload_file("payload.XXXXXX");
+ ScopedTempFile payload_file("payload.XXXXXX");
PayloadGenerationConfig config;
config.version.major = kBrilloMajorPayloadVersion;
PayloadFile payload;
diff --git a/payload_generator/squashfs_filesystem.cc b/payload_generator/squashfs_filesystem.cc
index 6152d7d..a41e283 100644
--- a/payload_generator/squashfs_filesystem.cc
+++ b/payload_generator/squashfs_filesystem.cc
@@ -72,15 +72,10 @@
}
bool GetFileMapContent(const string& sqfs_path, string* map) {
- // Create a tmp file
- string map_file;
- TEST_AND_RETURN_FALSE(
- utils::MakeTempFile("squashfs_file_map.XXXXXX", &map_file, nullptr));
- ScopedPathUnlinker map_unlinker(map_file);
-
+ ScopedTempFile map_file("squashfs_file_map.XXXXXX");
// Run unsquashfs to get the system file map.
// unsquashfs -m <map-file> <squashfs-file>
- vector<string> cmd = {"unsquashfs", "-m", map_file, sqfs_path};
+ vector<string> cmd = {"unsquashfs", "-m", map_file.path(), sqfs_path};
string stdout, stderr;
int exit_code;
if (!Subprocess::SynchronousExec(cmd, &exit_code, &stdout, &stderr) ||
@@ -89,7 +84,7 @@
<< stdout << " and stderr content: " << stderr;
return false;
}
- TEST_AND_RETURN_FALSE(utils::ReadFile(map_file, map));
+ TEST_AND_RETURN_FALSE(utils::ReadFile(map_file.path(), map));
return true;
}