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
This commit is contained in:
David Anderson 2018-11-09 16:11:14 -08:00 committed by Mark Salyzyn
parent 6009a2debc
commit a14f111377

View file

@ -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();
}