Add rpmMkdirs() to librpmio

- allows creating bunch of directories including parents at once
This commit is contained in:
Panu Matilainen 2008-10-10 14:28:41 +03:00
parent 1566caf067
commit a7ece3bc4a
2 changed files with 33 additions and 0 deletions

View File

@ -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;
}

View File

@ -62,6 +62,16 @@ FD_t rpmMkTempFile(const char * prefix, char **fn);
*/
int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid);
/** \ingroup rpmfileutil
* Create several directories (including parents if needed) in one go.
* Macros in pathstr will be expanded in the process.
* @param root leading root directory (or NULL for none)
* @param pathstr list of directories separated with :
* @return 0 if all directories were successfully created
* (or already existed), non-zero otherwise
*/
int rpmMkdirs(const char *root, const char *pathstr);
/** \ingroup rpmfileutil
* Canonicalize file path.
* @param path path to canonicalize (in-place)