diff options
author | Tianjie Xu <xunchang@google.com> | 2017-11-06 20:04:34 +0100 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-11-06 20:04:34 +0100 |
commit | 16a4cbe79b3b8a010f783a4ea7121f90a844cc0a (patch) | |
tree | a9a7e7a70e52ac3f64c08e8bb99a9a907976a1b6 /applypatch | |
parent | Merge "Clean up fuse_sideload and add a testcase." am: 73dca3e983 (diff) | |
parent | Merge "Switch to bionic gtest in bootable/recovery" (diff) | |
download | android_bootable_recovery-16a4cbe79b3b8a010f783a4ea7121f90a844cc0a.tar android_bootable_recovery-16a4cbe79b3b8a010f783a4ea7121f90a844cc0a.tar.gz android_bootable_recovery-16a4cbe79b3b8a010f783a4ea7121f90a844cc0a.tar.bz2 android_bootable_recovery-16a4cbe79b3b8a010f783a4ea7121f90a844cc0a.tar.lz android_bootable_recovery-16a4cbe79b3b8a010f783a4ea7121f90a844cc0a.tar.xz android_bootable_recovery-16a4cbe79b3b8a010f783a4ea7121f90a844cc0a.tar.zst android_bootable_recovery-16a4cbe79b3b8a010f783a4ea7121f90a844cc0a.zip |
Diffstat (limited to '')
-rw-r--r-- | applypatch/applypatch.cpp | 18 | ||||
-rw-r--r-- | applypatch/freecache.cpp | 7 | ||||
-rw-r--r-- | applypatch/include/applypatch/applypatch.h | 11 |
3 files changed, 17 insertions, 19 deletions
diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index c8b75df79..2153b5f19 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -42,6 +42,8 @@ #include "otafault/ota_io.h" #include "otautil/print_sha1.h" +std::string cache_temp_source = "/cache/saved.file"; + static int LoadPartitionContents(const std::string& filename, FileContents* file); static size_t FileSink(const unsigned char* data, size_t len, int fd); static int GenerateTarget(const FileContents& source_file, const std::unique_ptr<Value>& patch, @@ -411,12 +413,10 @@ int applypatch_check(const char* filename, const std::vector<std::string>& patch (!patch_sha1_str.empty() && FindMatchingPatch(file.sha1, patch_sha1_str) < 0)) { printf("file \"%s\" doesn't have any of expected sha1 sums; checking cache\n", filename); - // If the source file is missing or corrupted, it might be because - // we were killed in the middle of patching it. A copy of it - // should have been made in CACHE_TEMP_SOURCE. If that file - // exists and matches the sha1 we're looking for, the check still - // passes. - if (LoadFileContents(CACHE_TEMP_SOURCE, &file) != 0) { + // If the source file is missing or corrupted, it might be because we were killed in the middle + // of patching it. A copy of it should have been made in cache_temp_source. If that file + // exists and matches the sha1 we're looking for, the check still passes. + if (LoadFileContents(cache_temp_source.c_str(), &file) != 0) { printf("failed to load cache file\n"); return 1; } @@ -539,7 +539,7 @@ int applypatch(const char* source_filename, const char* target_filename, printf("source file is bad; trying copy\n"); FileContents copy_file; - if (LoadFileContents(CACHE_TEMP_SOURCE, ©_file) < 0) { + if (LoadFileContents(cache_temp_source.c_str(), ©_file) < 0) { printf("failed to read copy file\n"); return 1; } @@ -634,7 +634,7 @@ static int GenerateTarget(const FileContents& source_file, const std::unique_ptr printf("not enough free space on /cache\n"); return 1; } - if (SaveFileContents(CACHE_TEMP_SOURCE, &source_file) < 0) { + if (SaveFileContents(cache_temp_source.c_str(), &source_file) < 0) { printf("failed to back up source file\n"); return 1; } @@ -680,7 +680,7 @@ static int GenerateTarget(const FileContents& source_file, const std::unique_ptr } // Delete the backup copy of the source. - unlink(CACHE_TEMP_SOURCE); + unlink(cache_temp_source.c_str()); // Success! return 0; diff --git a/applypatch/freecache.cpp b/applypatch/freecache.cpp index 331cae265..0a40baa97 100644 --- a/applypatch/freecache.cpp +++ b/applypatch/freecache.cpp @@ -90,10 +90,9 @@ static std::set<std::string> FindExpendableFiles() { while ((de = readdir(d.get())) != 0) { std::string path = std::string(dirs[i]) + "/" + de->d_name; - // We can't delete CACHE_TEMP_SOURCE; if it's there we might have - // restarted during installation and could be depending on it to - // be there. - if (path == CACHE_TEMP_SOURCE) { + // We can't delete cache_temp_source; if it's there we might have restarted during + // installation and could be depending on it to be there. + if (path == cache_temp_source) { continue; } diff --git a/applypatch/include/applypatch/applypatch.h b/applypatch/include/applypatch/applypatch.h index 2a3b3ef39..bcb8a4126 100644 --- a/applypatch/include/applypatch/applypatch.h +++ b/applypatch/include/applypatch/applypatch.h @@ -36,12 +36,11 @@ struct FileContents { struct stat st; }; -// When there isn't enough room on the target filesystem to hold the -// patched version of the file, we copy the original here and delete -// it to free up space. If the expected source file doesn't exist, or -// is corrupted, we look to see if this file contains the bits we want -// and use it as the source instead. -#define CACHE_TEMP_SOURCE "/cache/saved.file" +// When there isn't enough room on the target filesystem to hold the patched version of the file, +// we copy the original here and delete it to free up space. If the expected source file doesn't +// exist, or is corrupted, we look to see if the cached file contains the bits we want and use it as +// the source instead. The default location for the cached source is "/cache/saved.file". +extern std::string cache_temp_source; using SinkFn = std::function<size_t(const unsigned char*, size_t)>; |