AssetCaches no longer keep all .CACHE entries. If an entry does not exist on the file system, it is not added to the cache. As a result of this, dud entries are cleared whenever the cache file is written to disk.
parent
abf9b299b5
commit
977af72999
|
@ -48,6 +48,17 @@ int AssetCache::fromFile(const char *cache_file) {
|
|||
while ((ret = fscanf_s(file, "%s %u %u\n", fpath, 1024, &fsum, &fsize)) != EOF) {
|
||||
#else
|
||||
while ((ret = fscanf(file, "%s %u %u\n", fpath, &fsum, &fsize)) != EOF) {
|
||||
#endif
|
||||
char fullpath[1024];
|
||||
snprintf(fullpath, 1024, "%s/%s", directory.c_str(), fpath);
|
||||
// only add the asset if it exists.
|
||||
#ifdef _WIN32
|
||||
DWORD file_attrib = GetFileAttributes(fullpath);
|
||||
if (file_attrib != INVALID_FILE_ATTRIBUTES) {
|
||||
#else
|
||||
// NOTE: TOCTOU/race vulnerability exists here, but I don't think it matters.
|
||||
struct stat fstat;
|
||||
if (stat(fullpath, &fstat) == 0) {
|
||||
#endif
|
||||
Asset *asset = new Asset();
|
||||
asset->filename.assign(fpath);
|
||||
|
@ -57,6 +68,7 @@ int AssetCache::fromFile(const char *cache_file) {
|
|||
assets->set(fpath, asset);
|
||||
LOG(LOG_DEBUG) << "opened " << fpath << " " << fsum << " " << fsize;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -71,10 +83,10 @@ int AssetCache::fromDir(const char *dir) {
|
|||
#else
|
||||
sprintf_s(cachepath, 1024, "%s/.CACHE", dir);
|
||||
#endif
|
||||
directory.assign(dir);
|
||||
if (fromFile(cachepath) != 0) {
|
||||
LOG(LOG_INFO) << FUNC_NAME << ": " << cachepath << " does not exist";
|
||||
}
|
||||
directory.assign(dir);
|
||||
traverseDir_r("");
|
||||
// TODO: move this to a "genChecksum()" sort of function
|
||||
/*HashEntry<Asset*> *entry;
|
||||
|
|
Loading…
Reference in New Issue