summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2015-04-20 09:49:35 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-04-20 09:49:36 +0000
commit4d0cb5e8064cecb25cd7bce7e9932f95a9bef7f4 (patch)
tree179ec28c64a68b0944fffa77615f4f64b924cf81
parent34c91eddb09ab86ffe6c965b25c5253c37ded227 (diff)
parente1d5a6aa5c4fc150c990bd160548aa8738bc51dc (diff)
downloadsystem_core-4d0cb5e8064cecb25cd7bce7e9932f95a9bef7f4.zip
system_core-4d0cb5e8064cecb25cd7bce7e9932f95a9bef7f4.tar.gz
system_core-4d0cb5e8064cecb25cd7bce7e9932f95a9bef7f4.tar.bz2
Merge "Reserve space on disk using fallocate"
-rw-r--r--libziparchive/zip_archive.cc17
1 files changed, 16 insertions, 1 deletions
diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc
index 57c46a3..8582344 100644
--- a/libziparchive/zip_archive.cc
+++ b/libziparchive/zip_archive.cc
@@ -1131,7 +1131,22 @@ int32_t ExtractEntryToFile(ZipArchiveHandle handle,
return kIoError;
}
- int result = TEMP_FAILURE_RETRY(ftruncate(fd, declared_length + current_offset));
+ int result = 0;
+#if defined(__linux__)
+ // Make sure we have enough space on the volume to extract the compressed
+ // entry. Note that the call to ftruncate below will change the file size but
+ // will not allocate space on disk.
+ if (declared_length > 0) {
+ result = TEMP_FAILURE_RETRY(fallocate(fd, 0, current_offset, declared_length));
+ if (result == -1) {
+ ALOGW("Zip: unable to allocate space for file to %" PRId64 ": %s",
+ static_cast<int64_t>(declared_length + current_offset), strerror(errno));
+ return kIoError;
+ }
+ }
+#endif // defined(__linux__)
+
+ result = TEMP_FAILURE_RETRY(ftruncate(fd, declared_length + current_offset));
if (result == -1) {
ALOGW("Zip: unable to truncate file to %" PRId64 ": %s",
static_cast<int64_t>(declared_length + current_offset), strerror(errno));