[sheepdog] [PATCH 2/8] util: add a helper to purge directory
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Mon Mar 11 06:25:27 CET 2013
At Mon, 11 Mar 2013 13:12:09 +0800,
Liu Yuan wrote:
>
> On 03/11/2013 01:09 PM, MORITA Kazutaka wrote:
> > I don't like such a big macro from the point of view of code
> > readability and maintainability. Is there no other way to do the same
> > thing?
>
> Neither do me. I have searched a lot for a better means, but I didn't
> get answer. I'd happy to replace this big macro. Any suggestions?
Is the following patch wrong?
-- >8 --
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)
{
More information about the sheepdog
mailing list