diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2008-10-10 14:28:41 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2008-10-10 14:28:41 +0300 |
commit | a7ece3bc4ac90b7bc68522aa748e138b78ce4179 (patch) | |
tree | 62cbd51442390281e4f02f6beeaf5bf03f511e18 /rpmio/rpmfileutil.c | |
parent | 1566caf0674b372a7b9ea481a90df0f2e8e7aec9 (diff) | |
download | rpm-a7ece3bc4ac90b7bc68522aa748e138b78ce4179.tar.gz |
Add rpmMkdirs() to librpmio
- allows creating bunch of directories including parents at once
Diffstat (limited to 'rpmio/rpmfileutil.c')
-rw-r--r-- | rpmio/rpmfileutil.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/rpmio/rpmfileutil.c b/rpmio/rpmfileutil.c index 60c4ba520..f4aed4ab2 100644 --- a/rpmio/rpmfileutil.c +++ b/rpmio/rpmfileutil.c @@ -704,3 +704,26 @@ char * rpmGetCwd(void) return currDir; } +int rpmMkdirs(const char *root, const char *pathstr) +{ + ARGV_t dirs = NULL; + int rc = 0; + argvSplit(&dirs, pathstr, ":"); + + for (char **d = dirs; *d; d++) { + char *path = rpmGetPath(root ? root : "", "/", *d, NULL); + if ((rc = rpmioMkpath(path, 0755, -1, -1)) != 0) { + const char *msg = _("failed to create directory"); + /* try to be more informative if the failing part was a macro */ + if (**d == '%') { + rpmlog(RPMLOG_ERR, "%s %s: %s: %m\n", msg, *d, path); + } else { + rpmlog(RPMLOG_ERR, "%s %s: %m\n", msg, path); + } + } + free(path); + if (rc) break; + } + argvFree(dirs); + return rc; +} |