Don't skip dot files when cleaning cache

This commit is contained in:
Kacper Gutowski 2018-07-05 03:39:27 +02:00 committed by Bert Münnich
parent 1613b42411
commit e6c9218319
4 changed files with 12 additions and 6 deletions

2
main.c
View file

@ -889,7 +889,7 @@ int main(int argc, char **argv)
continue; continue;
} }
start = fileidx; start = fileidx;
while ((filename = r_readdir(&dir)) != NULL) { while ((filename = r_readdir(&dir, true)) != NULL) {
check_add_file(filename, false); check_add_file(filename, false);
free((void*) filename); free((void*) filename);
} }

2
sxiv.h
View file

@ -364,7 +364,7 @@ void error(int, int, const char*, ...);
void size_readable(float*, const char**); void size_readable(float*, const char**);
int r_opendir(r_dir_t*, const char*, bool); int r_opendir(r_dir_t*, const char*, bool);
int r_closedir(r_dir_t*); int r_closedir(r_dir_t*);
char* r_readdir(r_dir_t*); char* r_readdir(r_dir_t*, bool);
int r_mkdir(char*); int r_mkdir(char*);

View file

@ -131,7 +131,7 @@ void tns_clean_cache(tns_t *tns)
dirlen = strlen(cache_dir); dirlen = strlen(cache_dir);
while ((cfile = r_readdir(&dir)) != NULL) { while ((cfile = r_readdir(&dir, false)) != NULL) {
filename = cfile + dirlen; filename = cfile + dirlen;
delete = false; delete = false;

10
util.c
View file

@ -134,7 +134,7 @@ int r_closedir(r_dir_t *rdir)
return ret; return ret;
} }
char* r_readdir(r_dir_t *rdir) char* r_readdir(r_dir_t *rdir, bool skip_dotfiles)
{ {
size_t len; size_t len;
char *filename; char *filename;
@ -143,8 +143,14 @@ char* r_readdir(r_dir_t *rdir)
while (true) { while (true) {
if (rdir->dir != NULL && (dentry = readdir(rdir->dir)) != NULL) { if (rdir->dir != NULL && (dentry = readdir(rdir->dir)) != NULL) {
if (dentry->d_name[0] == '.') if (dentry->d_name[0] == '.') {
if (skip_dotfiles)
continue; continue;
if (dentry->d_name[1] == '\0')
continue;
if (dentry->d_name[1] == '.' && dentry->d_name[2] == '\0')
continue;
}
len = strlen(rdir->name) + strlen(dentry->d_name) + 2; len = strlen(rdir->name) + strlen(dentry->d_name) + 2;
filename = (char*) emalloc(len); filename = (char*) emalloc(len);