From a14f1113770100eb9c0e7cdde4b990a78c552148 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 9 Nov 2018 16:11:14 -0800 Subject: [PATCH] liblp: Use TMPDIR instead of P_tmpdir. lpmake should be using the intermediates directory for temporary work rather than /tmp. Add ability to respect TMPDIR environment as inherited from TemporaryFile. Bug: 119313545 Test: manual test Change-Id: I1a0317538875ee37fb4066602ff7a75e4658d74b --- fs_mgr/liblp/images.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/fs_mgr/liblp/images.cpp b/fs_mgr/liblp/images.cpp index a46836e30..9e64de16a 100644 --- a/fs_mgr/liblp/images.cpp +++ b/fs_mgr/liblp/images.cpp @@ -299,7 +299,7 @@ bool SparseBuilder::AddPartitionImage(const LpMetadataPartition& partition, uint64_t partition_size = ComputePartitionSize(partition); if (file_length > partition_size) { LERROR << "Image for partition '" << GetPartitionName(partition) - << "' is greater than its size (" << file_length << ", excepted " << partition_size + << "' is greater than its size (" << file_length << ", expected " << partition_size << ")"; return false; } @@ -419,25 +419,19 @@ int SparseBuilder::OpenImageFile(const std::string& file) { return fd; } - char temp_file[PATH_MAX]; - snprintf(temp_file, sizeof(temp_file), "%s/imageXXXXXX", P_tmpdir); - android::base::unique_fd temp_fd(mkstemp(temp_file)); - if (temp_fd < 0) { - PERROR << "mkstemp failed"; - return -1; - } - if (unlink(temp_file) < 0) { - PERROR << "unlink failed"; + TemporaryFile tf; + if (tf.fd < 0) { + PERROR << "make temporary file failed"; return -1; } // We temporarily unsparse the file, rather than try to merge its chunks. - int rv = sparse_file_write(source.get(), temp_fd, false, false, false); + int rv = sparse_file_write(source.get(), tf.fd, false, false, false); if (rv) { LERROR << "sparse_file_write failed with code: " << rv; return -1; } - temp_fds_.push_back(std::move(temp_fd)); + temp_fds_.push_back(android::base::unique_fd(tf.release())); return temp_fds_.back().get(); }