diff options
author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2021-11-28 04:37:59 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2021-11-28 04:37:59 +0300 |
commit | 7b0eaa806f2cfc84e4c26f8f608e1d4e4843ea05 (patch) | |
tree | fd7ca9abad667e43c75aa09580dd145448ff72a5 /include/fs.h | |
parent | e2a71b0366aa80a7cf131fdbde6012671493d364 (diff) | |
download | revela-7b0eaa806f2cfc84e4c26f8f608e1d4e4843ea05.tar.gz revela-7b0eaa806f2cfc84e4c26f8f608e1d4e4843ea05.zip |
Clean out old files/dirs
Delete extraneous files/images/albums that are no longer present in the
source directory.
Diffstat (limited to 'include/fs.h')
-rw-r--r-- | include/fs.h | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/include/fs.h b/include/fs.h index 973d585..218958b 100644 --- a/include/fs.h +++ b/include/fs.h @@ -1,10 +1,17 @@ #ifndef REVELA_FS_H #define REVELA_FS_H -#include <stdio.h> #include <stdbool.h> #include <sys/stat.h> +#include "hashmap.h" + +enum nmkdir_res { + NMKDIR_ERROR, + NMKDIR_NOOP, + NMKDIR_CREATED, +}; + /* * Returns a pointer to where the basename of the file is inside path. */ @@ -14,7 +21,7 @@ const char *rbasename(const char *path); * Makes a new directory if it doesn't exist. If there were errors returns * false, otherwise returns true. */ -bool nmkdir(const char *path, struct stat *dstat, bool dry); +enum nmkdir_res nmkdir(const char *path, struct stat *dstat, bool dry); #define joinpathb(buf, a, b) sprintf(buf, "%s/%s", a, b) @@ -42,6 +49,16 @@ int file_is_uptodate(const char *path, const struct timespec *srcmtim); */ void setdatetime(const char *path, const struct timespec *mtim); +bool rmentry(const char *path); + +/* + * Recursively deletes extaneous files from directory, keeping files in the + * preserved hashmap. Returns -1 on error, number of deleted entries on success. + * The number is not the total number of files on all subdirectories, but only + * the number of files/dirs deleted from the directory pointed by path. + */ +ssize_t rmextra(const char *path, struct hashmap *preserved); + /* * Copies file(s) truncating and overwritting the file(s) in the destination * path if they exist and are not a directory, or creating them if they don't @@ -49,6 +66,7 @@ void setdatetime(const char *path, const struct timespec *mtim); * recursively. Only copies the regular files that already exist if their * timestamps do not match. */ -bool filesync(const char *restrict srcpath, const char *restrict dstpath); +bool filesync(const char *restrict srcpath, const char *restrict dstpath, + struct hashmap *preserved); #endif |