summaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-07-12 21:22:47 -0400
committerDavid Robillard <d@drobilla.net>2016-07-12 21:22:47 -0400
commit9da2f26c8a8fcd533c61e9cfafb92a653131f285 (patch)
treeaf6566c6a367a51ef72001513d08c062ab9a69a4 /src/util.c
parent689dff64ba1aef04e3115562d07bb1910de68059 (diff)
downloadlilv-9da2f26c8a8fcd533c61e9cfafb92a653131f285.tar.gz
lilv-9da2f26c8a8fcd533c61e9cfafb92a653131f285.tar.bz2
lilv-9da2f26c8a8fcd533c61e9cfafb92a653131f285.zip
Fix state file versioning
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c46
1 files changed, 18 insertions, 28 deletions
diff --git a/src/util.c b/src/util.c
index a0127f5..5b38259 100644
--- a/src/util.c
+++ b/src/util.c
@@ -370,26 +370,8 @@ lilv_path_join(const char* a, const char* b)
return path;
}
-static void
-lilv_size_mtime(const char* path, off_t* size, time_t* time)
-{
- struct stat buf;
- if (stat(path, &buf)) {
- LILV_ERRORF("stat(%s) (%s)\n", path, strerror(errno));
- return;
- }
-
- if (size) {
- *size = buf.st_size;
- }
- if (time) {
- *time = buf.st_mtime;
- }
-}
-
typedef struct {
char* pattern;
- off_t orig_size;
time_t time;
char* latest;
} Latest;
@@ -397,16 +379,18 @@ typedef struct {
static void
update_latest(const char* path, const char* name, void* data)
{
- Latest* latest = (Latest*)data;
- char* entry_path = lilv_path_join(path, name);
+ Latest* latest = (Latest*)data;
+ char* entry_path = lilv_path_join(path, name);
unsigned num;
if (sscanf(entry_path, latest->pattern, &num) == 1) {
- off_t entry_size = 0;
- time_t entry_time = 0;
- lilv_size_mtime(entry_path, &entry_size, &entry_time);
- if (entry_size == latest->orig_size && entry_time >= latest->time) {
- free(latest->latest);
- latest->latest = entry_path;
+ struct stat st;
+ if (!stat(entry_path, &st)) {
+ if (st.st_mtime >= latest->time) {
+ free(latest->latest);
+ latest->latest = entry_path;
+ }
+ } else {
+ LILV_ERRORF("stat(%s) (%s)\n", path, strerror(errno));
}
}
if (entry_path != latest->latest) {
@@ -419,8 +403,14 @@ char*
lilv_get_latest_copy(const char* path, const char* copy_path)
{
char* copy_dir = lilv_dirname(copy_path);
- Latest latest = { lilv_strjoin(copy_path, "%u", NULL), 0, 0, NULL };
- lilv_size_mtime(path, &latest.orig_size, &latest.time);
+ Latest latest = { lilv_strjoin(copy_path, ".%u", NULL), 0, NULL };
+
+ struct stat st;
+ if (!stat(path, &st)) {
+ latest.time = st.st_mtime;
+ } else {
+ LILV_ERRORF("stat(%s) (%s)\n", path, strerror(errno));
+ }
lilv_dir_for_each(copy_dir, &latest, update_latest);