Dolda2000 GitWeb
/
utils.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
f2bcbba
)
nextep: Remove empty data directories when unsetting values.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Fri, 30 Sep 2011 13:13:22 +0000
(15:13 +0200)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Fri, 30 Sep 2011 13:13:22 +0000
(15:13 +0200)
nextep.c
patch
|
blob
|
blame
|
history
diff --git
a/nextep.c
b/nextep.c
index
0a8b6b6
..
151db93
100644
(file)
--- a/
nextep.c
+++ b/
nextep.c
@@
-3,6
+3,7
@@
#include <unistd.h>
#include <string.h>
#include <libgen.h>
#include <unistd.h>
#include <string.h>
#include <libgen.h>
+#include <dirent.h>
#include <errno.h>
#include <sys/stat.h>
#include <errno.h>
#include <sys/stat.h>
@@
-15,6
+16,26
@@
static int ensuredir(char *base, char *dir)
return(0);
}
return(0);
}
+static void checkempty(char *dir)
+{
+ DIR *dh;
+ int empty;
+ struct dirent *de;
+
+ if((dh = opendir(dir)) == NULL)
+ return;
+ empty = 1;
+ while((de = readdir(dh)) != NULL) {
+ if(de->d_name[0] != '.') {
+ empty = 0;
+ break;
+ }
+ }
+ closedir(dh);
+ if(empty)
+ rmdir(dir);
+}
+
static void usage(FILE *out)
{
fprintf(out, "usage: nextep [-h] [-f FILE] [-s SET-VALUE] [DIR]\n");
static void usage(FILE *out)
{
fprintf(out, "usage: nextep [-h] [-f FILE] [-s SET-VALUE] [DIR]\n");
@@
-81,6
+102,7
@@
int main(int argc, char **argv)
fprintf(stderr, "nextep: %s: %s\n", fpath, strerror(errno));
exit(1);
}
fprintf(stderr, "nextep: %s: %s\n", fpath, strerror(errno));
exit(1);
}
+ checkempty(base);
} else {
if(ensuredir(buf, base)) {
fprintf(stderr, "nextep: %s: %s\n", base, strerror(errno));
} else {
if(ensuredir(buf, base)) {
fprintf(stderr, "nextep: %s: %s\n", base, strerror(errno));