mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
virfile: Introduce virFileRemoveLastComponent
Move some parts of virStorageFileRemoveLastPathComponent into a separate function so they can be reused. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
be1a7e6d31
commit
7fccf12482
@ -1517,6 +1517,7 @@ virFileReadHeaderFD;
|
|||||||
virFileReadLimFD;
|
virFileReadLimFD;
|
||||||
virFileRelLinkPointsTo;
|
virFileRelLinkPointsTo;
|
||||||
virFileRemove;
|
virFileRemove;
|
||||||
|
virFileRemoveLastComponent;
|
||||||
virFileResolveAllLinks;
|
virFileResolveAllLinks;
|
||||||
virFileResolveLink;
|
virFileResolveLink;
|
||||||
virFileRewrite;
|
virFileRewrite;
|
||||||
|
@ -3132,6 +3132,23 @@ virFileSanitizePath(const char *path)
|
|||||||
return cleanpath;
|
return cleanpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virFileRemoveLastComponent:
|
||||||
|
*
|
||||||
|
* For given path cut off the last component. If there's no dir
|
||||||
|
* separator (whole path is one file name), @path is turned into
|
||||||
|
* an empty string.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
virFileRemoveLastComponent(char *path)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
if ((tmp = strrchr(path, VIR_FILE_DIR_SEPARATOR)))
|
||||||
|
tmp[1] = '\0';
|
||||||
|
else
|
||||||
|
path[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virFilePrintf:
|
* virFilePrintf:
|
||||||
|
@ -268,6 +268,7 @@ bool virFileIsAbsPath(const char *path);
|
|||||||
int virFileAbsPath(const char *path,
|
int virFileAbsPath(const char *path,
|
||||||
char **abspath) ATTRIBUTE_RETURN_CHECK;
|
char **abspath) ATTRIBUTE_RETURN_CHECK;
|
||||||
const char *virFileSkipRoot(const char *path);
|
const char *virFileSkipRoot(const char *path);
|
||||||
|
void virFileRemoveLastComponent(char *path);
|
||||||
|
|
||||||
int virFileOpenTty(int *ttymaster,
|
int virFileOpenTty(int *ttymaster,
|
||||||
char **ttyName,
|
char **ttyName,
|
||||||
|
@ -2868,16 +2868,12 @@ virStorageFileCanonicalizePath(const char *path,
|
|||||||
static char *
|
static char *
|
||||||
virStorageFileRemoveLastPathComponent(const char *path)
|
virStorageFileRemoveLastPathComponent(const char *path)
|
||||||
{
|
{
|
||||||
char *tmp;
|
|
||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
if (VIR_STRDUP(ret, path ? path : "") < 0)
|
if (VIR_STRDUP(ret, path ? path : "") < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((tmp = strrchr(ret, '/')))
|
virFileRemoveLastComponent(ret);
|
||||||
tmp[1] = '\0';
|
|
||||||
else
|
|
||||||
ret[0] = '\0';
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user