Remove the old log files if cache space is insufficient for OTA

We set the limit of the max stash size to 80% of cache size. But the
cache space can still be insufficient for the update if the log files
occupy a large chunk of /cache. So remove the old logs for now to make
room for the update.

Bug: 77528881
Test: unit tests pass
Change-Id: Ia8bcb0ace11f8164ad9290bfb360e08e31d282cb
This commit is contained in:
Tianjie Xu
2018-04-11 14:38:09 -07:00
parent ea8a6a9af2
commit d5fbcc1ba9
6 changed files with 277 additions and 66 deletions

View File

@@ -436,13 +436,13 @@ static size_t FileSink(const unsigned char* data, size_t len, int fd) {
// Return the amount of free space (in bytes) on the filesystem
// containing filename. filename must exist. Return -1 on error.
size_t FreeSpaceForFile(const char* filename) {
struct statfs sf;
if (statfs(filename, &sf) != 0) {
printf("failed to statfs %s: %s\n", filename, strerror(errno));
return -1;
}
return sf.f_bsize * sf.f_bavail;
size_t FreeSpaceForFile(const std::string& filename) {
struct statfs sf;
if (statfs(filename.c_str(), &sf) != 0) {
printf("failed to statfs %s: %s\n", filename.c_str(), strerror(errno));
return -1;
}
return sf.f_bsize * sf.f_bavail;
}
int CacheSizeCheck(size_t bytes) {