Same as quit, rm -f ~/.cmus/cache, start cmus.
---
Doc/cmus.txt | 8 ++++++--
cache.c | 14 +++++++++++---
cache.h | 2 +-
cmus.c | 9 +++++++--
cmus.h | 2 +-
command_mode.c | 5 +++--
job.c | 4 +++-
job.h | 4 ++++
8 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/Doc/cmus.txt b/Doc/cmus.txt
index 477d656..255fe3d 100644
--- a/Doc/cmus.txt
+++ b/Doc/cmus.txt
@@ -590,8 +590,12 @@ unbind [-f] <context> <key>
unmark
Unmark all tracks (see *mark*).
-update-cache
- Update track metadata cache (~/.cmus/cache).
+update-cache [-f]
+ Update track metadata cache (~/.cmus/cache). Only files with changed
+ modification time or removed files are considered.
+
+ -f
+ Update all files. Same as quit, rm -f ~/.cmus/cache, start cmus.
view <name or 1-7>
Switches active view.
diff --git a/cache.c b/cache.c
index 5f2b30d..9b5c85d 100644
--- a/cache.c
+++ b/cache.c
@@ -424,7 +424,7 @@ struct track_info *cache_get_ti(const char *filename)
return ti;
}
-struct track_info **cache_refresh(int *count)
+struct track_info **cache_refresh(int *count, int force)
{
struct track_info **tis = get_track_infos();
int i, n = total;
@@ -446,7 +446,7 @@ struct track_info **cache_refresh(int *count)
if (!is_url(ti->filename)) {
rc = stat(ti->filename, &st);
- if (!rc && ti->mtime == st.st_mtime) {
+ if (!rc && !force && ti->mtime == st.st_mtime) {
// unchanged
tis[i] = NULL;
continue;
@@ -459,8 +459,16 @@ struct track_info **cache_refresh(int *count)
if (!rc) {
// changed
- struct track_info *new_ti = ip_get_ti(ti->filename);
+ struct track_info *new_ti;
+ // clear cache-only entries
+ if (force && ti->ref == 1) {
+ track_info_unref(ti);
+ tis[i] = NULL;
+ continue;
+ }
+
+ new_ti = ip_get_ti(ti->filename);
if (new_ti) {
add_ti(new_ti, hash);
new++;
diff --git a/cache.h b/cache.h
index 680f0b1..71ac2a0 100644
--- a/cache.h
+++ b/cache.h
@@ -31,6 +31,6 @@ int cache_init(void);
int cache_close(void);
struct track_info *cache_get_ti(const char *filename);
void cache_remove_ti(struct track_info *ti);
-struct track_info **cache_refresh(int *count);
+struct track_info **cache_refresh(int *count, int force);
#endif
diff --git a/cmus.c b/cmus.c
index 0d869fd..f998dee 100644
--- a/cmus.c
+++ b/cmus.c
@@ -250,9 +250,14 @@ static int update_cb(void *data, struct track_info *ti)
return 0;
}
-void cmus_update_cache(void)
+void cmus_update_cache(int force)
{
- worker_add_job(JOB_TYPE_LIB, do_update_cache_job, free_update_cache_job, NULL);
+ struct update_cache_data *data;
+
+ data = xnew(struct update_cache_data, 1);
+ data->force = force;
+
+ worker_add_job(JOB_TYPE_LIB, do_update_cache_job, free_update_cache_job, data);
}
void cmus_update_lib(void)
diff --git a/cmus.h b/cmus.h
index 6cf5fbd..7ef14b0 100644
--- a/cmus.h
+++ b/cmus.h
@@ -76,7 +76,7 @@ void cmus_add(add_ti_cb, const char *name, enum file_type ft, int jt);
int cmus_save(for_each_ti_cb for_each_ti, const char *filename);
int cmus_save_ext(for_each_ti_cb for_each_ti, const char *filename);
-void cmus_update_cache(void);
+void cmus_update_cache(int force);
void cmus_update_lib(void);
void cmus_update_tis(struct track_info **tis, int nr);
diff --git a/command_mode.c b/command_mode.c
index 642d21e..f1e928e 100644
--- a/command_mode.c
+++ b/command_mode.c
@@ -613,7 +613,8 @@ static void cmd_unmark(char *arg)
static void cmd_update_cache(char *arg)
{
- cmus_update_cache();
+ int flag = parse_flags((const char **)&arg, "f");
+ cmus_update_cache(flag == 'f');
}
static void cmd_cd(char *arg)
@@ -2439,7 +2440,7 @@ struct command commands[] = {
{ "tqueue", cmd_tqueue, 0, 1, NULL, 0, 0 },
{ "unbind", cmd_unbind, 1, 1, expand_unbind_args, 0, 0 },
{ "unmark", cmd_unmark, 0, 0, NULL, 0, 0 },
- { "update-cache", cmd_update_cache,0, 0, NULL, 0, 0 },
+ { "update-cache", cmd_update_cache,0, 1, NULL, 0, 0 },
{ "view", cmd_view, 1, 1, NULL, 0, 0 },
{ "vol", cmd_vol, 1, 2, NULL, 0, 0 },
{ "w", cmd_save, 0, 1, expand_load_save, 0, CMD_UNSAFE },
diff --git a/job.c b/job.c
index d10e391..6a10bdb 100644
--- a/job.c
+++ b/job.c
@@ -280,11 +280,12 @@ void free_update_job(void *data)
void do_update_cache_job(void *data)
{
+ struct update_cache_data *d = data;
struct track_info **tis;
int i, count;
cache_lock();
- tis = cache_refresh(&count);
+ tis = cache_refresh(&count, d->force);
editable_lock();
for (i = 0; i < count; i++) {
struct track_info *new, *old = tis[i];
@@ -308,4 +309,5 @@ void do_update_cache_job(void *data)
void free_update_cache_job(void *data)
{
+ free(data);
}
diff --git a/job.h b/job.h
index c94369b..a9807b0 100644
--- a/job.h
+++ b/job.h
@@ -33,6 +33,10 @@ struct update_data {
struct track_info **ti;
};
+struct update_cache_data {
+ unsigned int force : 1;
+};
+
void do_add_job(void *data);
void free_add_job(void *data);
void do_update_job(void *data);
--
1.7.5.1