[sheepdog] [PATCH v2 2/7] util: add a helper to purge directory
Liu Yuan
namei.unix at gmail.com
Mon Mar 11 09:19:28 CET 2013
From: Liu Yuan <tailai.ly at taobao.com>
This is preparation patch for md series.
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
include/util.h | 1 +
lib/util.c | 18 ++++++++++++++----
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/include/util.h b/include/util.h
index 3307d7e..eae4e9a 100644
--- a/include/util.h
+++ b/include/util.h
@@ -84,6 +84,7 @@ ssize_t xpread(int fd, void *buf, size_t count, off_t offset);
ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset);
void pstrcpy(char *buf, int buf_size, const char *str);
int rmdir_r(char *dir_path);
+int purge_directory(char *dir_path);
bool is_numeric(const char *p);
int install_sighandler(int signum, void (*handler)(int), bool once);
int install_crash_handler(void (*handler)(int));
diff --git a/lib/util.c b/lib/util.c
index 41396da..2282025 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -255,8 +255,8 @@ void notrace pstrcpy(char *buf, int buf_size, const char *str)
*q = '\0';
}
-/* remove directory recursively */
-int rmdir_r(char *dir_path)
+/* Purge directory recursively */
+int purge_directory(char *dir_path)
{
int ret;
struct stat s;
@@ -293,13 +293,23 @@ int rmdir_r(char *dir_path)
goto out;
}
}
-
- ret = rmdir(dir_path);
out:
closedir(dir);
return ret;
}
+/* remove directory recursively */
+int rmdir_r(char *dir_path)
+{
+ int ret;
+
+ ret = purge_directory(dir_path);
+ if (ret == 0)
+ ret = rmdir(dir_path);
+
+ return ret;
+}
+
/* Trim zero sectors from the beginning and end of buffer */
void trim_zero_sectors(void *buf, uint64_t *offset, uint32_t *len)
{
--
1.7.9.5
More information about the sheepdog
mailing list