dovecot-2.2: unlink_directory(): Added UNLINK_DIRECTORY_FLAG_SKI...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Oct 8 00:01:12 EEST 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/b9cb9c3cdfdc
changeset: 15191:b9cb9c3cdfdc
user: Timo Sirainen <tss at iki.fi>
date: Mon Oct 08 00:00:55 2012 +0300
description:
unlink_directory(): Added UNLINK_DIRECTORY_FLAG_SKIP_DOTFILES flag.
diffstat:
src/lib-storage/list/mailbox-list-delete.c | 2 +-
src/lib/unlink-directory.c | 25 ++++++++++++++-----------
src/lib/unlink-directory.h | 9 ++++++++-
3 files changed, 23 insertions(+), 13 deletions(-)
diffs (108 lines):
diff -r 60c4815778fb -r b9cb9c3cdfdc src/lib-storage/list/mailbox-list-delete.c
--- a/src/lib-storage/list/mailbox-list-delete.c Thu Oct 04 02:34:53 2012 +0300
+++ b/src/lib-storage/list/mailbox-list-delete.c Mon Oct 08 00:00:55 2012 +0300
@@ -313,7 +313,7 @@
int mailbox_list_delete_trash(const char *path)
{
- if (unlink_directory(path, TRUE) < 0) {
+ if (unlink_directory(path, UNLINK_DIRECTORY_FLAG_RMDIR) < 0) {
if (errno == ELOOP) {
/* it's a symlink? try just deleting it */
if (unlink(path) == 0)
diff -r 60c4815778fb -r b9cb9c3cdfdc src/lib/unlink-directory.c
--- a/src/lib/unlink-directory.c Thu Oct 04 02:34:53 2012 +0300
+++ b/src/lib/unlink-directory.c Mon Oct 08 00:00:55 2012 +0300
@@ -40,7 +40,8 @@
#include <dirent.h>
#include <sys/stat.h>
-static int unlink_directory_r(const char *dir)
+static int
+unlink_directory_r(const char *dir, enum unlink_directory_flags flags)
{
DIR *dirp;
struct dirent *d;
@@ -97,11 +98,14 @@
errno = 0;
while ((d = readdir(dirp)) != NULL) {
- if (d->d_name[0] == '.' &&
- (d->d_name[1] == '\0' ||
- (d->d_name[1] == '.' && d->d_name[2] == '\0'))) {
- /* skip . and .. */
- continue;
+ if (d->d_name[0] == '.') {
+ if ((d->d_name[1] == '\0' ||
+ (d->d_name[1] == '.' && d->d_name[2] == '\0'))) {
+ /* skip . and .. */
+ continue;
+ }
+ if ((flags & UNLINK_DIRECTORY_FLAG_SKIP_DOTFILES) != 0)
+ continue;
}
if (unlink(d->d_name) < 0 && errno != ENOENT) {
@@ -112,7 +116,7 @@
break;
errno = 0;
} else if (S_ISDIR(st.st_mode)) {
- if (unlink_directory_r(d->d_name) < 0) {
+ if (unlink_directory_r(d->d_name, flags) < 0) {
if (errno != ENOENT)
break;
errno = 0;
@@ -159,7 +163,7 @@
return 0;
}
-int unlink_directory(const char *dir, bool unlink_dir)
+int unlink_directory(const char *dir, enum unlink_directory_flags flags)
{
int fd, ret, old_errno;
@@ -167,7 +171,7 @@
if (fd == -1)
return -1;
- ret = unlink_directory_r(dir);
+ ret = unlink_directory_r(dir, flags);
if (ret < 0 && errno == ENOENT)
ret = 0;
old_errno = errno;
@@ -183,7 +187,7 @@
return -1;
}
- if (unlink_dir) {
+ if ((flags & UNLINK_DIRECTORY_FLAG_RMDIR) != 0) {
if (rmdir(dir) < 0 && errno != ENOENT) {
if (errno == EEXIST) {
/* standardize errno */
@@ -192,6 +196,5 @@
return -1;
}
}
-
return 0;
}
diff -r 60c4815778fb -r b9cb9c3cdfdc src/lib/unlink-directory.h
--- a/src/lib/unlink-directory.h Thu Oct 04 02:34:53 2012 +0300
+++ b/src/lib/unlink-directory.h Mon Oct 08 00:00:55 2012 +0300
@@ -1,8 +1,15 @@
#ifndef UNLINK_DIRECTORY_H
#define UNLINK_DIRECTORY_H
+enum unlink_directory_flags {
+ /* After unlinking all files, rmdir() the directory itself */
+ UNLINK_DIRECTORY_FLAG_RMDIR = 0x01,
+ /* Don't unlink any files beginning with "." */
+ UNLINK_DIRECTORY_FLAG_SKIP_DOTFILES = 0x02
+};
+
/* Unlink directory and/or everything under it.
Returns 0 if successful, -1 if error. */
-int unlink_directory(const char *dir, bool unlink_dir);
+int unlink_directory(const char *dir, enum unlink_directory_flags flags);
#endif
More information about the dovecot-cvs
mailing list