mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
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: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit c321bfc5c3
)
This commit is contained in:
parent
5b2b1f7fbd
commit
a0d964a815
@ -1194,6 +1194,7 @@ virFileIsLink;
|
||||
virFileLinkPointsTo;
|
||||
virFileLock;
|
||||
virFileLoopDeviceAssociate;
|
||||
virFileMakeParentPath;
|
||||
virFileMakePath;
|
||||
virFileMakePathWithMode;
|
||||
virFileMatchesNameSuffix;
|
||||
|
@ -2174,6 +2174,35 @@ cleanup:
|
||||
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
|
||||
* associated with a persistent guest or network */
|
||||
char *
|
||||
|
@ -187,6 +187,7 @@ int virDirCreate(const char *path, mode_t mode, uid_t uid, gid_t gid,
|
||||
int virFileMakePath(const char *path) ATTRIBUTE_RETURN_CHECK;
|
||||
int virFileMakePathWithMode(const char *path,
|
||||
mode_t mode) ATTRIBUTE_RETURN_CHECK;
|
||||
int virFileMakeParentPath(const char *path) ATTRIBUTE_RETURN_CHECK;
|
||||
|
||||
char *virFileBuildPath(const char *dir,
|
||||
const char *name,
|
||||
|
Loading…
Reference in New Issue
Block a user