Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8cea6774 authored by David Anderson's avatar David Anderson Committed by android-build-merger
Browse files

liblp: Use TMPDIR instead of P_tmpdir.

am: a14f1113

Change-Id: I39f0ec7f95d6adfbb82d20d7a5896fa5bd91a029
parents eb96a0a0 a14f1113
Loading
Loading
Loading
Loading
+6 −12
Original line number Original line Diff line number Diff line
@@ -299,7 +299,7 @@ bool SparseBuilder::AddPartitionImage(const LpMetadataPartition& partition,
    uint64_t partition_size = ComputePartitionSize(partition);
    uint64_t partition_size = ComputePartitionSize(partition);
    if (file_length > partition_size) {
    if (file_length > partition_size) {
        LERROR << "Image for partition '" << GetPartitionName(partition)
        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;
        return false;
    }
    }
@@ -419,25 +419,19 @@ int SparseBuilder::OpenImageFile(const std::string& file) {
        return fd;
        return fd;
    }
    }


    char temp_file[PATH_MAX];
    TemporaryFile tf;
    snprintf(temp_file, sizeof(temp_file), "%s/imageXXXXXX", P_tmpdir);
    if (tf.fd < 0) {
    android::base::unique_fd temp_fd(mkstemp(temp_file));
        PERROR << "make temporary file failed";
    if (temp_fd < 0) {
        PERROR << "mkstemp failed";
        return -1;
    }
    if (unlink(temp_file) < 0) {
        PERROR << "unlink failed";
        return -1;
        return -1;
    }
    }


    // We temporarily unsparse the file, rather than try to merge its chunks.
    // 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) {
    if (rv) {
        LERROR << "sparse_file_write failed with code: " << rv;
        LERROR << "sparse_file_write failed with code: " << rv;
        return -1;
        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();
    return temp_fds_.back().get();
}
}