Skip to content

Commit

Permalink
Fix: respect the setting for disabling cache pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Jun 15, 2024
1 parent 3087785 commit f65377e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
34 changes: 15 additions & 19 deletions src/lib/cache_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,31 @@ static int crop_dir(sds cache_basedir, const char *type, int keepdays);
// public functions

/**
* Clears the caches
* @param cachedir covercache directory
* @param keepdays delete files older than this number of days
* @return deleted file count on success, else -1
* Clears the caches unconditionally
* @param config pointer to static config
*/
void cache_disk_clear(struct t_config *config) {
if (config->cache_cover_keep_days > CACHE_DISK_DISABLED) {
crop_dir(config->cachedir, DIR_CACHE_COVER, config->cache_cover_keep_days);
}
if (config->cache_lyrics_keep_days > CACHE_DISK_DISABLED) {
crop_dir(config->cachedir, DIR_CACHE_LYRICS, config->cache_lyrics_keep_days);
}
if (config->cache_thumbs_keep_days > CACHE_DISK_DISABLED) {
crop_dir(config->cachedir, DIR_CACHE_THUMBS, config->cache_thumbs_keep_days);
}
crop_dir(config->cachedir, DIR_CACHE_COVER, config->cache_cover_keep_days);
crop_dir(config->cachedir, DIR_CACHE_LYRICS, config->cache_lyrics_keep_days);
crop_dir(config->cachedir, DIR_CACHE_THUMBS, config->cache_thumbs_keep_days);
crop_dir(config->cachedir, DIR_CACHE_MISC, config->cache_misc_keep_days);
}

/**
* Crops the caches
* @param cachedir covercache directory
* @param keepdays delete files older than this number of days
* @return deleted file count on success, else -1
* @param config pointer to static config
*/
void cache_disk_crop(struct t_config *config) {
crop_dir(config->cachedir, DIR_CACHE_COVER, 0);
crop_dir(config->cachedir, DIR_CACHE_LYRICS, 0);
if (config->cache_cover_keep_days > CACHE_DISK_DISABLED) {
crop_dir(config->cachedir, DIR_CACHE_COVER, 0);
}
if (config->cache_lyrics_keep_days > CACHE_DISK_DISABLED) {
crop_dir(config->cachedir, DIR_CACHE_LYRICS, 0);
}
if (config->cache_thumbs_keep_days > CACHE_DISK_DISABLED) {
crop_dir(config->cachedir, DIR_CACHE_THUMBS, 0);
}
crop_dir(config->cachedir, DIR_CACHE_MISC, 0);
crop_dir(config->cachedir, DIR_CACHE_THUMBS, 0);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/mympd_api/timer_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* Private definitions
*/

static void timer_handler_covercache_crop(void);
static void timer_handler_cache_disk_crop(void);
static void timer_handler_smartpls_update(void);
static void timer_handler_caches_create(void);

Expand All @@ -46,7 +46,7 @@ void timer_handler_by_id(unsigned timer_id, struct t_timer_definition *definitio
(void) definition; // not used
switch(timer_id) {
case TIMER_ID_DISK_CACHE_CROP:
timer_handler_covercache_crop();
timer_handler_cache_disk_crop();
break;
case TIMER_ID_SMARTPLS_UPDATE:
timer_handler_smartpls_update();
Expand Down Expand Up @@ -183,10 +183,10 @@ bool mympd_api_timer_startplay(struct t_partition_state *partition_state,
*/

/**
* Timer handler for timer_id TIMER_ID_COVERCACHE_CROP
* Timer handler for timer_id TIMER_ID_DISK_CACHE_CROP
*/
static void timer_handler_covercache_crop(void) {
MYMPD_LOG_INFO(NULL, "Start timer_handler_covercache_crop");
static void timer_handler_cache_disk_crop(void) {
MYMPD_LOG_INFO(NULL, "Start timer_handler_cache_disk_crop");
struct t_work_request *request = create_request(REQUEST_TYPE_DISCARD, 0, 0, MYMPD_API_CACHE_DISK_CROP, NULL, MPD_PARTITION_DEFAULT);
request->data = jsonrpc_end(request->data);
push_request(request, 0);
Expand Down

0 comments on commit f65377e

Please sign in to comment.