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.

master
kts 2015-03-01 06:07:50 -08:00
parent abf9b299b5
commit 977af72999
1 changed files with 20 additions and 8 deletions

View File

@ -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) { while ((ret = fscanf_s(file, "%s %u %u\n", fpath, 1024, &fsum, &fsize)) != EOF) {
#else #else
while ((ret = fscanf(file, "%s %u %u\n", fpath, &fsum, &fsize)) != EOF) { 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 #endif
Asset *asset = new Asset(); Asset *asset = new Asset();
asset->filename.assign(fpath); asset->filename.assign(fpath);
@ -57,6 +68,7 @@ int AssetCache::fromFile(const char *cache_file) {
assets->set(fpath, asset); assets->set(fpath, asset);
LOG(LOG_DEBUG) << "opened " << fpath << " " << fsum << " " << fsize; LOG(LOG_DEBUG) << "opened " << fpath << " " << fsum << " " << fsize;
} }
}
return 0; return 0;
} }
@ -71,10 +83,10 @@ int AssetCache::fromDir(const char *dir) {
#else #else
sprintf_s(cachepath, 1024, "%s/.CACHE", dir); sprintf_s(cachepath, 1024, "%s/.CACHE", dir);
#endif #endif
directory.assign(dir);
if (fromFile(cachepath) != 0) { if (fromFile(cachepath) != 0) {
LOG(LOG_INFO) << FUNC_NAME << ": " << cachepath << " does not exist"; LOG(LOG_INFO) << FUNC_NAME << ": " << cachepath << " does not exist";
} }
directory.assign(dir);
traverseDir_r(""); traverseDir_r("");
// TODO: move this to a "genChecksum()" sort of function // TODO: move this to a "genChecksum()" sort of function
/*HashEntry<Asset*> *entry; /*HashEntry<Asset*> *entry;