* [gentoo-commits] gentoo-projects commit in portage-utils/libq: libq.c xmkdir.c
@ 2011-02-23 8:59 Mike Frysinger (vapier)
0 siblings, 0 replies; only message in thread
From: Mike Frysinger (vapier) @ 2011-02-23 8:59 UTC (permalink / raw
To: gentoo-commits
vapier 11/02/23 08:59:45
Modified: libq.c
Added: xmkdir.c
Log:
replace `rm -rf` shells with an internal rm_rf(), and add support for running pkg_{pre,post}inst ourselves
Revision Changes Path
1.22 portage-utils/libq/libq.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.c?rev=1.22&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.c?rev=1.22&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.c?r1=1.21&r2=1.22
Index: libq.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/libq.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- libq.c 19 Jul 2010 00:25:13 -0000 1.21
+++ libq.c 23 Feb 2011 08:59:45 -0000 1.22
@@ -23,6 +23,7 @@
#include "safe_io.c"
#include "xchdir.c"
#include "xgetcwd.c"
+#include "xmkdir.c"
#include "xreadlink.c"
#include "xsystem.c"
1.1 portage-utils/libq/xmkdir.c
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?rev=1.1&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmkdir.c?rev=1.1&content-type=text/plain
Index: xmkdir.c
===================================================================
/* Emulate `mkdir -p -m MODE PATH` */
static int mkdir_p(const char *path, mode_t mode)
{
char *_p, *p, *s;
_p = p = xstrdup(path);
while (1) {
/* Skip duplicate slashes */
while (*p == '/')
++p;
/* Find the next path element */
s = strchr(p, '/');
if (!s)
break;
/* Make it */
*s = '\0';
mkdir(_p, mode);
*s = '/';
p = s;
}
free(_p);
return 0;
}
/* Emulate `rm -rf PATH` */
static int _rm_rf_subdir(int dfd, const char *path)
{
int subdfd;
DIR *dir;
struct dirent *de;
subdfd = openat(dfd, path, O_RDONLY|O_CLOEXEC|O_NOFOLLOW);
if (subdfd < 0)
return -1;
dir = fdopendir(subdfd);
if (!dir) {
close(subdfd);
return -1;
}
while ((de = readdir(dir)) != NULL) {
if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
continue;
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);
unlinkat(subdfd, de->d_name, AT_REMOVEDIR);
}
}
/* this also does close(subdfd); */
closedir(dir);
return 0;
}
static int rm_rf(const char *path)
{
_rm_rf_subdir(AT_FDCWD, path);
if (rmdir(path) == 0)
return 0;
/* if path is a symlink, unlink it */
if (unlink(path) == 0)
return 0;
/* XXX: we don't handle:
* trailing slashes: `rm -rf a/b/c/` -> need to change to a/b/c */
return -1;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-02-23 8:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-23 8:59 [gentoo-commits] gentoo-projects commit in portage-utils/libq: libq.c xmkdir.c 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