Loading base/file.cpp +32 −6 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include <errno.h> #include <errno.h> #include <fcntl.h> #include <fcntl.h> #include <ftw.h> #include <libgen.h> #include <libgen.h> #include <stdio.h> #include <stdio.h> #include <stdlib.h> #include <stdlib.h> Loading @@ -30,11 +31,6 @@ #include <string> #include <string> #include <vector> #include <vector> #include "android-base/logging.h" #include "android-base/macros.h" // For TEMP_FAILURE_RETRY on Darwin. #include "android-base/unique_fd.h" #include "android-base/utf8.h" #if defined(__APPLE__) #if defined(__APPLE__) #include <mach-o/dyld.h> #include <mach-o/dyld.h> #endif #endif Loading @@ -47,6 +43,11 @@ #define OS_PATH_SEPARATOR '/' #define OS_PATH_SEPARATOR '/' #endif #endif #include "android-base/logging.h" // and must be after windows.h for ERROR #include "android-base/macros.h" // For TEMP_FAILURE_RETRY on Darwin. #include "android-base/unique_fd.h" #include "android-base/utf8.h" #ifdef _WIN32 #ifdef _WIN32 int mkstemp(char* template_name) { int mkstemp(char* template_name) { if (_mktemp(template_name) == nullptr) { if (_mktemp(template_name) == nullptr) { Loading Loading @@ -133,7 +134,32 @@ TemporaryDir::TemporaryDir() { } } TemporaryDir::~TemporaryDir() { TemporaryDir::~TemporaryDir() { rmdir(path); auto callback = [](const char* child, const struct stat*, int file_type, struct FTW*) -> int { switch (file_type) { case FTW_D: case FTW_DP: case FTW_DNR: if (rmdir(child) == -1) { PLOG(ERROR) << "rmdir " << child; } break; case FTW_NS: default: if (rmdir(child) != -1) break; // FALLTHRU (for gcc, lint, pcc, etc; and following for clang) FALLTHROUGH_INTENDED; case FTW_F: case FTW_SL: case FTW_SLN: if (unlink(child) == -1) { PLOG(ERROR) << "unlink " << child; } break; } return 0; }; nftw(path, callback, 128, FTW_DEPTH | FTW_MOUNT | FTW_PHYS); } } bool TemporaryDir::init(const std::string& tmp_dir) { bool TemporaryDir::init(const std::string& tmp_dir) { Loading fs_mgr/liblp/images.cpp +6 −12 Original line number Original line Diff line number Diff line Loading @@ -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; } } Loading Loading @@ -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(); } } Loading Loading
base/file.cpp +32 −6 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include <errno.h> #include <errno.h> #include <fcntl.h> #include <fcntl.h> #include <ftw.h> #include <libgen.h> #include <libgen.h> #include <stdio.h> #include <stdio.h> #include <stdlib.h> #include <stdlib.h> Loading @@ -30,11 +31,6 @@ #include <string> #include <string> #include <vector> #include <vector> #include "android-base/logging.h" #include "android-base/macros.h" // For TEMP_FAILURE_RETRY on Darwin. #include "android-base/unique_fd.h" #include "android-base/utf8.h" #if defined(__APPLE__) #if defined(__APPLE__) #include <mach-o/dyld.h> #include <mach-o/dyld.h> #endif #endif Loading @@ -47,6 +43,11 @@ #define OS_PATH_SEPARATOR '/' #define OS_PATH_SEPARATOR '/' #endif #endif #include "android-base/logging.h" // and must be after windows.h for ERROR #include "android-base/macros.h" // For TEMP_FAILURE_RETRY on Darwin. #include "android-base/unique_fd.h" #include "android-base/utf8.h" #ifdef _WIN32 #ifdef _WIN32 int mkstemp(char* template_name) { int mkstemp(char* template_name) { if (_mktemp(template_name) == nullptr) { if (_mktemp(template_name) == nullptr) { Loading Loading @@ -133,7 +134,32 @@ TemporaryDir::TemporaryDir() { } } TemporaryDir::~TemporaryDir() { TemporaryDir::~TemporaryDir() { rmdir(path); auto callback = [](const char* child, const struct stat*, int file_type, struct FTW*) -> int { switch (file_type) { case FTW_D: case FTW_DP: case FTW_DNR: if (rmdir(child) == -1) { PLOG(ERROR) << "rmdir " << child; } break; case FTW_NS: default: if (rmdir(child) != -1) break; // FALLTHRU (for gcc, lint, pcc, etc; and following for clang) FALLTHROUGH_INTENDED; case FTW_F: case FTW_SL: case FTW_SLN: if (unlink(child) == -1) { PLOG(ERROR) << "unlink " << child; } break; } return 0; }; nftw(path, callback, 128, FTW_DEPTH | FTW_MOUNT | FTW_PHYS); } } bool TemporaryDir::init(const std::string& tmp_dir) { bool TemporaryDir::init(const std::string& tmp_dir) { Loading
fs_mgr/liblp/images.cpp +6 −12 Original line number Original line Diff line number Diff line Loading @@ -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; } } Loading Loading @@ -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(); } } Loading