MCPcopy Create free account
hub / github.com/alibaba/CicadaPlayer / checkSpaceEnough

Method checkSpaceEnough

framework/cacheModule/cache/CacheChecker.cpp:94–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94bool CacheChecker::checkSpaceEnough()
95{
96 //list old cache files and remove old files to get enough space.
97 vector<CacheFileInfo> cacheFiles;
98 getAllCachedFiles(mCacheConfig.mCacheDir, cacheFiles);
99
100 if (cacheFiles.empty()) {
101 return true;
102 }
103
104 int64_t totalCacheLen = 0;
105
106 for (const CacheFileInfo &cacheFileInfo : cacheFiles) {
107 totalCacheLen += cacheFileInfo.length;
108 }
109
110 int64_t MAX_DIR_SIZE = mCacheConfig.mMaxDirSizeMB * 1024 * 1024;
111
112 if (totalCacheLen + mMediaSize < MAX_DIR_SIZE) {
113 //space is enough
114 return true;
115 }
116
117 int64_t leftSpaceIfDeleteFile = totalCacheLen;
118
119 for (const CacheFileInfo &cacheFileInfo : cacheFiles) {
120 leftSpaceIfDeleteFile -= cacheFileInfo.length;
121
122 if (leftSpaceIfDeleteFile + mMediaSize < MAX_DIR_SIZE) {
123 //remove this , space is enough
124 bool ret = FileUtils::rmrf(cacheFileInfo.path.c_str());
125 return ret;
126 } else {
127 //remove this is NOT enough yet,remove and continue
128 bool ret = FileUtils::rmrf(cacheFileInfo.path.c_str());
129 }
130 }
131
132 return false;
133}
134
135
136bool compare(const CacheFileInfo &a, const CacheFileInfo &b)

Callers 1

checkCanCacheMethod · 0.80

Calls 1

emptyMethod · 0.45

Tested by

no test coverage detected