提交 c321bfc5 编写于 作者: D Daniel P. Berrange

Add virFileMakeParentPath helper function

Add a helper function which takes a file path and ensures
that all directory components leading up to the file exist.
IOW, it strips the filename part of the path and passes
the result to virFileMakePath.
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 c3eb12ca
...@@ -1228,6 +1228,7 @@ virFileIsMountPoint; ...@@ -1228,6 +1228,7 @@ virFileIsMountPoint;
virFileLinkPointsTo; virFileLinkPointsTo;
virFileLock; virFileLock;
virFileLoopDeviceAssociate; virFileLoopDeviceAssociate;
virFileMakeParentPath;
virFileMakePath; virFileMakePath;
virFileMakePathWithMode; virFileMakePathWithMode;
virFileMatchesNameSuffix; virFileMatchesNameSuffix;
......
...@@ -2340,6 +2340,35 @@ cleanup: ...@@ -2340,6 +2340,35 @@ cleanup:
return ret; return ret;
} }
int
virFileMakeParentPath(const char *path)
{
char *p;
char *tmp;
int ret = -1;
VIR_DEBUG("path=%s", path);
if (VIR_STRDUP(tmp, path) < 0) {
errno = ENOMEM;
return -1;
}
if ((p = strrchr(tmp, '/')) == NULL) {
errno = EINVAL;
goto cleanup;
}
*p = '\0';
ret = virFileMakePathHelper(tmp, 0777);
cleanup:
VIR_FREE(tmp);
return ret;
}
/* Build up a fully qualified path for a config file to be /* Build up a fully qualified path for a config file to be
* associated with a persistent guest or network */ * associated with a persistent guest or network */
char * char *
......
...@@ -198,6 +198,7 @@ int virDirCreate(const char *path, mode_t mode, uid_t uid, gid_t gid, ...@@ -198,6 +198,7 @@ int virDirCreate(const char *path, mode_t mode, uid_t uid, gid_t gid,
int virFileMakePath(const char *path) ATTRIBUTE_RETURN_CHECK; int virFileMakePath(const char *path) ATTRIBUTE_RETURN_CHECK;
int virFileMakePathWithMode(const char *path, int virFileMakePathWithMode(const char *path,
mode_t mode) ATTRIBUTE_RETURN_CHECK; mode_t mode) ATTRIBUTE_RETURN_CHECK;
int virFileMakeParentPath(const char *path) ATTRIBUTE_RETURN_CHECK;
char *virFileBuildPath(const char *dir, char *virFileBuildPath(const char *dir,
const char *name, const char *name,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册