* [gentoo-commits] gentoo-projects commit in portage-utils/libq: xmkdir.c
@ 2011-03-02 1:18 Mike Frysinger (vapier)
0 siblings, 0 replies; 4+ messages in thread
From: Mike Frysinger (vapier) @ 2011-03-02 1:18 UTC (permalink / raw
To: gentoo-commits
vapier 11/03/02 01:18:02
Modified: xmkdir.c
Log:
optimize a bit, and make sure we dont need a trailing slash for the last dir component
Revision Changes Path
1.2 portage-utils/libq/xmkdir.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?rev=1.2&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?rev=1.2&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?r1=1.1&r2=1.2
Index: xmkdir.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/xmkdir.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- xmkdir.c 23 Feb 2011 08:59:45 -0000 1.1
+++ xmkdir.c 2 Mar 2011 01:18:02 -0000 1.2
@@ -3,17 +3,25 @@
{
char *_p, *p, *s;
+ /* Assume that most of the time, only the last element
+ * is missing. So if we can mkdir it right away, bail. */
+ if (mkdir(path, mode) == 0 || errno == EEXIST)
+ return 0;
+
+ /* Build up the whole tree */
_p = p = xstrdup(path);
- while (1) {
+ while (*p) {
/* Skip duplicate slashes */
while (*p == '/')
++p;
/* Find the next path element */
s = strchr(p, '/');
- if (!s)
+ if (!s) {
+ mkdir(_p, mode);
break;
+ }
/* Make it */
*s = '\0';
^ permalink raw reply [flat|nested] 4+ messages in thread
* [gentoo-commits] gentoo-projects commit in portage-utils/libq: xmkdir.c
@ 2011-03-02 8:13 Mike Frysinger (vapier)
0 siblings, 0 replies; 4+ messages in thread
From: Mike Frysinger (vapier) @ 2011-03-02 8:13 UTC (permalink / raw
To: gentoo-commits
vapier 11/03/02 08:13:20
Modified: xmkdir.c
Log:
add a helper to prune empty dir trees
Revision Changes Path
1.3 portage-utils/libq/xmkdir.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?rev=1.3&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?rev=1.3&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?r1=1.2&r2=1.3
Index: xmkdir.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/xmkdir.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- xmkdir.c 2 Mar 2011 01:18:02 -0000 1.2
+++ xmkdir.c 2 Mar 2011 08:13:20 -0000 1.3
@@ -85,3 +85,24 @@
* trailing slashes: `rm -rf a/b/c/` -> need to change to a/b/c */
return -1;
}
+
+static int rmdir_r(const char *path)
+{
+ size_t len;
+ char *p, *e;
+
+ p = xstrdup_len(path, &len);
+ e = p + len;
+
+ while (e != p) {
+ if (rmdir(p) && errno == ENOTEMPTY)
+ break;
+ while (*e != '/' && e > p)
+ --e;
+ *e = '\0';
+ }
+
+ free(p);
+
+ return 0;
+}
^ permalink raw reply [flat|nested] 4+ messages in thread
* [gentoo-commits] gentoo-projects commit in portage-utils/libq: xmkdir.c
@ 2011-03-02 9:14 Mike Frysinger (vapier)
0 siblings, 0 replies; 4+ messages in thread
From: Mike Frysinger (vapier) @ 2011-03-02 9:14 UTC (permalink / raw
To: gentoo-commits
vapier 11/03/02 09:14:12
Modified: xmkdir.c
Log:
expose the recursive deleters with *at style funcs
Revision Changes Path
1.4 portage-utils/libq/xmkdir.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?rev=1.4&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?rev=1.4&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?r1=1.3&r2=1.4
Index: xmkdir.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/xmkdir.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- xmkdir.c 2 Mar 2011 08:13:20 -0000 1.3
+++ xmkdir.c 2 Mar 2011 09:14:12 -0000 1.4
@@ -37,7 +37,7 @@
}
/* Emulate `rm -rf PATH` */
-static int _rm_rf_subdir(int dfd, const char *path)
+_q_static int rm_rf_at(int dfd, const char *path)
{
int subdfd;
DIR *dir;
@@ -59,7 +59,7 @@
if (unlinkat(subdfd, de->d_name, 0) == -1) {
if (errno != EISDIR)
errp("could not unlink %s", de->d_name);
- _rm_rf_subdir(subdfd, de->d_name);
+ rm_rf_at(subdfd, de->d_name);
unlinkat(subdfd, de->d_name, AT_REMOVEDIR);
}
}
@@ -70,9 +70,9 @@
return 0;
}
-static int rm_rf(const char *path)
+_q_static int rm_rf(const char *path)
{
- _rm_rf_subdir(AT_FDCWD, path);
+ rm_rf_at(AT_FDCWD, path);
if (rmdir(path) == 0)
return 0;
@@ -86,7 +86,7 @@
return -1;
}
-static int rmdir_r(const char *path)
+_q_static int rmdir_r_at(int dfd, const char *path)
{
size_t len;
char *p, *e;
@@ -95,7 +95,7 @@
e = p + len;
while (e != p) {
- if (rmdir(p) && errno == ENOTEMPTY)
+ if (unlinkat(dfd, p, AT_REMOVEDIR) && errno == ENOTEMPTY)
break;
while (*e != '/' && e > p)
--e;
@@ -106,3 +106,8 @@
return 0;
}
+
+_q_static int rmdir_r(const char *path)
+{
+ return rmdir_r_at(AT_FDCWD, path);
+}
^ permalink raw reply [flat|nested] 4+ messages in thread
* [gentoo-commits] gentoo-projects commit in portage-utils/libq: xmkdir.c
@ 2013-04-30 1:56 Mike Frysinger (vapier)
0 siblings, 0 replies; 4+ messages in thread
From: Mike Frysinger (vapier) @ 2013-04-30 1:56 UTC (permalink / raw
To: gentoo-commits
vapier 13/04/30 01:56:37
Modified: xmkdir.c
Log:
disable rmdir_r for now as no one uses it
Revision Changes Path
1.5 portage-utils/libq/xmkdir.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?rev=1.5&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?rev=1.5&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?r1=1.4&r2=1.5
Index: xmkdir.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/xmkdir.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- xmkdir.c 2 Mar 2011 09:14:12 -0000 1.4
+++ xmkdir.c 30 Apr 2013 01:56:37 -0000 1.5
@@ -107,7 +107,9 @@
return 0;
}
+/*
_q_static int rmdir_r(const char *path)
{
return rmdir_r_at(AT_FDCWD, path);
}
+*/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-04-30 1:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-02 9:14 [gentoo-commits] gentoo-projects commit in portage-utils/libq: xmkdir.c Mike Frysinger (vapier)
-- strict thread matches above, loose matches on Subject: below --
2013-04-30 1:56 Mike Frysinger (vapier)
2011-03-02 8:13 Mike Frysinger (vapier)
2011-03-02 1:18 Mike Frysinger (vapier)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox