diff options
author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2021-11-29 19:53:34 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2021-11-29 19:53:34 +0300 |
commit | 8e07de9d952f8f27273296f1b6ae58550ce1e98b (patch) | |
tree | c653d6d2b4a2e2251ce0ff44ad4740d91e20b1da /src/components.c | |
parent | ef0a23b0636a8c7f4a3c802ff76645261e8b225f (diff) | |
download | revela-8e07de9d952f8f27273296f1b6ae58550ce1e98b.tar.gz revela-8e07de9d952f8f27273296f1b6ae58550ce1e98b.zip |
Update adjacent images to inserted/removed
Now the program checks if the html of the next and previous images was
updated if a new image was inserted or an old image removed, and updates
them if needed.
Also make rmextra and filesync respect dry run mode.
Diffstat (limited to 'src/components.c')
-rw-r--r-- | src/components.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/components.c b/src/components.c index 2e3bc5e..876cb39 100644 --- a/src/components.c +++ b/src/components.c @@ -72,7 +72,7 @@ static void image_date_from_stat(struct image *image, const struct stat *pstat, struct tm *date) { - image->tstamp = pstat->st_ctim.tv_sec; + image->tstamp = pstat->st_mtim.tv_sec; localtime_r(&image->tstamp, date); } @@ -123,6 +123,18 @@ out: } struct image * +image_old(struct stat *istat) +{ + struct image *image = calloc(1, sizeof *image); + if (image == NULL) { + log_printl_errno(LOG_FATAL, "Memory allocation error"); + return NULL; + } + image->tstamp = istat->st_mtim.tv_sec; + return image; +} + +struct image * image_new(char *src, const struct stat *pstat, struct album *album) { struct image *image = calloc(1, sizeof *image); @@ -159,6 +171,7 @@ image_new(char *src, const struct stat *pstat, struct album *album) image_set_date(image, pstat); image->map = hashmap_new_with_cap(8); image->thumb = hashmap_new_with_cap(4); + image->modified = false; return image; } @@ -180,13 +193,15 @@ image_destroy(void *data) if (image->exif_data) { exif_data_unref(image->exif_data); } - hashmap_free(image->map); - hashmap_free(image->thumb); + if (image->map) { + hashmap_free(image->map); + hashmap_free(image->thumb); + } free(image); } struct album * -album_new(struct album_config *conf, struct site_config *sconf, const char *src, +album_new(struct album_config *conf, struct site *site, const char *src, const char *rsrc, const struct stat *dstat) { struct album *album = calloc(1, sizeof *album); @@ -194,15 +209,16 @@ album_new(struct album_config *conf, struct site_config *sconf, const char *src, log_printl_errno(LOG_FATAL, "Memory allocation error"); return NULL; } + album->site = site; album->config = conf; album->source = strdup(src); - album->slug = slugify(rsrc, sconf->base_url, &album->url); + album->slug = slugify(rsrc, site->config->base_url, &album->url); album->images = bstree_new(image_cmp, image_destroy); album->tstamp = MAXTIME; - album->image_dirs = hashmap_new(); + album->preserved = hashmap_new(); album->map = hashmap_new_with_cap(16); album->thumbs = vector_new(128); - album->previews = vector_new(sconf->max_previews); + album->previews = vector_new(site->config->max_previews); return album; } @@ -242,7 +258,7 @@ album_destroy(void *data) free(album->source); free(album->url); bstree_destroy(album->images); - hashmap_free(album->image_dirs); + hashmap_free(album->preserved); hashmap_free(album->map); vector_free(album->thumbs); vector_free(album->previews); |