Skip to content

Commit

Permalink
Packages: don't cache values if we fail to acquire modify time
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Sep 13, 2024
1 parent 3d1a6b6 commit 9faa382
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/detection/packages/packages.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ bool ffPackagesReadCache(FFstrbuf* cacheDir, FFstrbuf* cacheContent, const char*
return true;
}

if (__builtin_expect(st.st_mtim.tv_sec <= 0, false))
return false;

uint64_t mtime_current = (uint64_t) st.st_mtim.tv_sec * 1000 + (uint64_t) st.st_mtim.tv_nsec / 1000000;

ffStrbufSet(cacheDir, &instance.state.platform.cacheDir);
Expand All @@ -57,6 +60,9 @@ bool ffPackagesReadCache(FFstrbuf* cacheDir, FFstrbuf* cacheContent, const char*

bool ffPackagesWriteCache(FFstrbuf* cacheDir, FFstrbuf* cacheContent, uint32_t num_elements)
{
if (__builtin_expect(cacheContent->length == 0, false))
return false;

ffStrbufAppendF(cacheContent, "%" PRIu32, num_elements);
return ffWriteFileBuffer(cacheDir->chars, cacheContent);
}

0 comments on commit 9faa382

Please sign in to comment.