diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c index aac052bf9eb..61825fa1360 100644 --- a/src/util/disk_cache.c +++ b/src/util/disk_cache.c @@ -146,6 +146,9 @@ disk_cache_type_create(const char *gpu_name, goto path_fail; } + if (!getenv("MESA_SHADER_CACHE_DIR") && !getenv("MESA_GLSL_CACHE_DIR")) + disk_cache_touch_cache_user_marker(cache->path); + cache->type = cache_type; cache->stats.enabled = debug_get_bool_option("MESA_SHADER_CACHE_SHOW_STATS", diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c index d8bd8a0f532..201041a7fce 100644 --- a/src/util/disk_cache_os.c +++ b/src/util/disk_cache_os.c @@ -96,6 +96,7 @@ disk_cache_get_function_identifier(void *ptr, struct mesa_sha1 *ctx) #include #include #include +#include "utime.h" #include "util/blob.h" #include "util/crc32.h" @@ -1044,6 +1045,29 @@ disk_cache_load_cache_index_foz(void *mem_ctx, struct disk_cache *cache) return foz_prepare(&cache->foz_db, cache->path); } + +void +disk_cache_touch_cache_user_marker(char *path) +{ + char *marker_path = NULL; + asprintf(&marker_path, "%s/marker", path); + if (!marker_path) + return; + + time_t now = time(NULL); + + struct stat attr; + if (stat(marker_path, &attr) == -1) { + int fd = open(marker_path, O_WRONLY | O_CREAT | O_CLOEXEC, 0644); + if (fd != -1) { + close(fd); + } + } else if (now - attr.st_mtime < 60 * 60 * 24 /* One day */) { + (void)utime(marker_path, NULL); + } + free(marker_path); +} + bool disk_cache_mmap_cache_index(void *mem_ctx, struct disk_cache *cache, char *path) diff --git a/src/util/disk_cache_os.h b/src/util/disk_cache_os.h index 0f5f3923304..2b543cf27be 100644 --- a/src/util/disk_cache_os.h +++ b/src/util/disk_cache_os.h @@ -161,6 +161,9 @@ disk_cache_enabled(void); bool disk_cache_load_cache_index_foz(void *mem_ctx, struct disk_cache *cache); +void +disk_cache_touch_cache_user_marker(char *path); + bool disk_cache_mmap_cache_index(void *mem_ctx, struct disk_cache *cache, char *path);