diff --git a/src/dircache.c b/src/dircache.c index 1445f63..1fb2367 100644 --- a/src/dircache.c +++ b/src/dircache.c @@ -192,7 +192,6 @@ struct dircache_entry *dircache_get(const char *path) #endif if (user_cb.stale) user_cb.stale(path, &e->dir_entry_list); - dircache_invalidate(path); return NULL; } } diff --git a/src/rar2fs.c b/src/rar2fs.c index 1e6f23b..08a335a 100644 --- a/src/rar2fs.c +++ b/src/rar2fs.c @@ -2601,8 +2601,10 @@ static void __listrar_tocache_forcedir(struct filecache_entry *entry_p, ****************************************************************************/ static inline void __listrar_cachedir(const char *mp) { + pthread_rwlock_wrlock(&dir_access_lock); if (!dircache_get(mp)) (void)dircache_alloc(mp); + pthread_rwlock_unlock(&dir_access_lock); } /*! @@ -2615,13 +2617,15 @@ static void __listrar_cachedirentry(const char *mp) char *tmp = safe_path; safe_path = __gnu_dirname(safe_path); if (CHRCMP(safe_path, '/')) { + pthread_rwlock_wrlock(&dir_access_lock); struct dircache_entry *dce = dircache_get(safe_path); if (dce) { - char *tmp = strdup(mp); - dir_entry_add(&dce->dir_entry_list, basename(tmp), + char *tmp2 = strdup(mp); + dir_entry_add(&dce->dir_entry_list, basename(tmp2), NULL, DIR_E_RAR); - free(tmp); + free(tmp2); } + pthread_rwlock_unlock(&dir_access_lock); } free(tmp); } @@ -4330,6 +4334,11 @@ static int __dircache_stale(const char *path, struct dir_entry_list *dir) free(mp); } pthread_rwlock_unlock(&file_access_lock); + /* Promote to a wrlock (might already be) */ + pthread_rwlock_unlock(&dir_access_lock); + pthread_rwlock_wrlock(&dir_access_lock); + dircache_invalidate(path); + return 0; }