}
if (forced ||
- !rspamd_re_cache_is_valid_hyperscan_file(ctx->cfg->re_cache,
- globbuf.gl_pathv[i], TRUE, TRUE, &err)) {
+ (!rspamd_re_cache_is_valid_hyperscan_file(ctx->cfg->re_cache,
+ globbuf.gl_pathv[i], TRUE, TRUE, &err) &&
+ !rspamd_hyperscan_is_file_known(globbuf.gl_pathv[i]))) {
if (unlink(globbuf.gl_pathv[i]) == -1) {
msg_err("cannot unlink %s: %s; reason for expiration: %e", globbuf.gl_pathv[i],
strerror(errno), err);
known_cached_files.erase(fpath.string());
}
+ auto is_file_known(const char *fname) -> bool
+ {
+ auto fpath = std::filesystem::path{fname};
+ std::error_code ec;
+
+ fpath = std::filesystem::canonical(fpath, ec);
+
+ if (ec && ec.value() != 0) {
+ /* File doesn't exist or can't be canonicalized - not known */
+ return false;
+ }
+
+ return known_cached_files.contains(fpath.string());
+ }
+
auto cleanup_maybe() -> void
{
auto env_cleanup_disable = std::getenv("RSPAMD_NO_CLEANUP");
rspamd::util::hs_known_files_cache::get().cleanup_maybe();
}
+gboolean rspamd_hyperscan_is_file_known(const char *fname)
+{
+ return rspamd::util::hs_known_files_cache::get().is_file_known(fname);
+}
+
void rspamd_hyperscan_notice_loaded(void)
{
rspamd::util::hs_known_files_cache::get().notice_loaded();
*/
void rspamd_hyperscan_cleanup_maybe(void);
+/**
+ * Check if a file is known to the hyperscan cache (has been noticed)
+ * @param fname path to check
+ * @return TRUE if the file is known
+ */
+gboolean rspamd_hyperscan_is_file_known(const char *fname);
+
/**
* Get a platform identifier string for hyperscan cache keys.
* This includes the hyperscan version, platform tune, and CPU features.