Commit 2aebbf84 authored by Max Kellermann's avatar Max Kellermann

directory: added "mtime" property

Remember the modification time of each directory. This is important for archives (which are virtual directories right now), but may also be useful for an automatic update mechanism.
parent 3d6e6416
...@@ -33,6 +33,7 @@ struct directory { ...@@ -33,6 +33,7 @@ struct directory {
struct dirvec children; struct dirvec children;
struct songvec songs; struct songvec songs;
struct directory *parent; struct directory *parent;
time_t mtime;
ino_t inode; ino_t inode;
dev_t device; dev_t device;
unsigned stat; /* not needed if ino_t == dev_t == 0 is impossible */ unsigned stat; /* not needed if ino_t == dev_t == 0 is impossible */
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#define DIRECTORY_MTIME "mtime: " /* DEPRECATED, noop-read-only */ #define DIRECTORY_MTIME "mtime: "
#define DIRECTORY_BEGIN "begin: " #define DIRECTORY_BEGIN "begin: "
#define DIRECTORY_END "end: " #define DIRECTORY_END "end: "
...@@ -41,6 +41,9 @@ directory_save(FILE *fp, struct directory *directory) ...@@ -41,6 +41,9 @@ directory_save(FILE *fp, struct directory *directory)
int retv; int retv;
if (!directory_is_root(directory)) { if (!directory_is_root(directory)) {
fprintf(fp, DIRECTORY_MTIME "%lu\n",
(unsigned long)directory->mtime);
retv = fprintf(fp, "%s%s\n", DIRECTORY_BEGIN, retv = fprintf(fp, "%s%s\n", DIRECTORY_BEGIN,
directory_get_path(directory)); directory_get_path(directory));
if (retv < 0) if (retv < 0)
...@@ -84,8 +87,12 @@ directory_load(FILE *fp, struct directory *directory) ...@@ -84,8 +87,12 @@ directory_load(FILE *fp, struct directory *directory)
strcpy(key, &(buffer[strlen(DIRECTORY_DIR)])); strcpy(key, &(buffer[strlen(DIRECTORY_DIR)]));
if (!fgets(buffer, sizeof(buffer), fp)) if (!fgets(buffer, sizeof(buffer), fp))
FATAL("Error reading db, fgets\n"); FATAL("Error reading db, fgets\n");
/* for compatibility with db's prior to 0.11 */
if (g_str_has_prefix(buffer, DIRECTORY_MTIME)) { if (g_str_has_prefix(buffer, DIRECTORY_MTIME)) {
directory->mtime =
g_ascii_strtoull(buffer + sizeof(DIRECTORY_MTIME) - 1,
NULL, 10);
if (!fgets(buffer, sizeof(buffer), fp)) if (!fgets(buffer, sizeof(buffer), fp))
FATAL("Error reading db, fgets\n"); FATAL("Error reading db, fgets\n");
} }
......
...@@ -360,10 +360,12 @@ update_archive_tree(struct directory *directory, char *name) ...@@ -360,10 +360,12 @@ update_archive_tree(struct directory *directory, char *name)
* *
* @param parent the parent directory the archive file resides in * @param parent the parent directory the archive file resides in
* @param name the UTF-8 encoded base name of the archive file * @param name the UTF-8 encoded base name of the archive file
* @param st stat() information on the archive file
* @param plugin the archive plugin which fits this archive type * @param plugin the archive plugin which fits this archive type
*/ */
static void static void
update_archive_file(struct directory *parent, const char *name, update_archive_file(struct directory *parent, const char *name,
const struct stat *st,
const struct archive_plugin *plugin) const struct archive_plugin *plugin)
{ {
char *path_fs; char *path_fs;
...@@ -393,6 +395,8 @@ update_archive_file(struct directory *parent, const char *name, ...@@ -393,6 +395,8 @@ update_archive_file(struct directory *parent, const char *name,
directory->device = DEVICE_INARCHIVE; directory->device = DEVICE_INARCHIVE;
} }
directory->mtime = st->st_mtime;
plugin->scan_reset(file); plugin->scan_reset(file);
while ((filepath = plugin->scan_next(file)) != NULL) { while ((filepath = plugin->scan_next(file)) != NULL) {
...@@ -438,7 +442,7 @@ update_regular_file(struct directory *directory, ...@@ -438,7 +442,7 @@ update_regular_file(struct directory *directory,
} }
#ifdef ENABLE_ARCHIVE #ifdef ENABLE_ARCHIVE
} else if ((archive = archive_plugin_from_suffix(suffix))) { } else if ((archive = archive_plugin_from_suffix(suffix))) {
update_archive_file(directory, name, archive); update_archive_file(directory, name, st, archive);
#endif #endif
} }
} }
...@@ -593,6 +597,8 @@ updateDirectory(struct directory *directory, const struct stat *st) ...@@ -593,6 +597,8 @@ updateDirectory(struct directory *directory, const struct stat *st)
closedir(dir); closedir(dir);
directory->mtime = st->st_mtime;
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment