mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +00:00
all: Use virFileCanonicalizePath() instead of canonicalize_file_name()
The latter is impossible to mock on platforms that use the gnulib implementation, such as FreeBSD, while the former doesn't suffer from this limitation. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
9190c37268
commit
4267393198
@ -160,7 +160,7 @@ virStorageFileBackendFileGetUniqueIdentifier(virStorageSourcePtr src)
|
|||||||
virStorageFileBackendFsPrivPtr priv = src->drv->priv;
|
virStorageFileBackendFsPrivPtr priv = src->drv->priv;
|
||||||
|
|
||||||
if (!priv->canonpath) {
|
if (!priv->canonpath) {
|
||||||
if (!(priv->canonpath = canonicalize_file_name(src->path))) {
|
if (!(priv->canonpath = virFileCanonicalizePath(src->path))) {
|
||||||
virReportSystemError(errno, _("can't canonicalize path '%s'"),
|
virReportSystemError(errno, _("can't canonicalize path '%s'"),
|
||||||
src->path);
|
src->path);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1597,7 +1597,7 @@ virFileResolveLinkHelper(const char *linkpath,
|
|||||||
return VIR_STRDUP_QUIET(*resultpath, linkpath) < 0 ? -1 : 0;
|
return VIR_STRDUP_QUIET(*resultpath, linkpath) < 0 ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
*resultpath = canonicalize_file_name(linkpath);
|
*resultpath = virFileCanonicalizePath(linkpath);
|
||||||
|
|
||||||
return *resultpath == NULL ? -1 : 0;
|
return *resultpath == NULL ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
@ -2622,7 +2622,7 @@ virPCIGetDeviceAddressFromSysfsLink(const char *device_link)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
device_path = canonicalize_file_name(device_link);
|
device_path = virFileCanonicalizePath(device_link);
|
||||||
if (device_path == NULL) {
|
if (device_path == NULL) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to resolve device link '%s'"),
|
_("Failed to resolve device link '%s'"),
|
||||||
|
@ -171,7 +171,7 @@ testPrepImages(void)
|
|||||||
fprintf(stderr, "unable to create directory %s\n", datadir "/dir");
|
fprintf(stderr, "unable to create directory %s\n", datadir "/dir");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (!(canondir = canonicalize_file_name(absdir))) {
|
if (!(canondir = virFileCanonicalizePath(absdir))) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ testPrepImages(void)
|
|||||||
fprintf(stderr, "unable to create raw file\n");
|
fprintf(stderr, "unable to create raw file\n");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (!(canonraw = canonicalize_file_name(absraw))) {
|
if (!(canonraw = virFileCanonicalizePath(absraw))) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ testPrepImages(void)
|
|||||||
"-F", "raw", "-b", "raw", "qcow2", NULL);
|
"-F", "raw", "-b", "raw", "qcow2", NULL);
|
||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
goto skip;
|
goto skip;
|
||||||
if (!(canonqcow2 = canonicalize_file_name(absqcow2))) {
|
if (!(canonqcow2 = virFileCanonicalizePath(absqcow2))) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -220,7 +220,7 @@ testPrepImages(void)
|
|||||||
virCommandAddArg(cmd, "wrap");
|
virCommandAddArg(cmd, "wrap");
|
||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
goto skip;
|
goto skip;
|
||||||
if (!(canonwrap = canonicalize_file_name(abswrap))) {
|
if (!(canonwrap = virFileCanonicalizePath(abswrap))) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -233,7 +233,7 @@ testPrepImages(void)
|
|||||||
virCommandAddArg(cmd, "qed");
|
virCommandAddArg(cmd, "qed");
|
||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
goto skip;
|
goto skip;
|
||||||
if (!(canonqed = canonicalize_file_name(absqed))) {
|
if (!(canonqed = virFileCanonicalizePath(absqed))) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -133,12 +133,11 @@ checkPath(const char *path)
|
|||||||
virAsprintfQuiet(&relPath, "./%s", path) < 0)
|
virAsprintfQuiet(&relPath, "./%s", path) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* Le sigh. Both canonicalize_file_name() and realpath()
|
/* Le sigh. virFileCanonicalizePath() expects @path to exist, otherwise
|
||||||
* expect @path to exist otherwise they return an error. So
|
* it will return an error. So if we are called over an non-existent
|
||||||
* if we are called over an non-existent file, this could
|
* file, this could return an error. In that case do our best and hope
|
||||||
* return an error. In that case do our best and hope we will
|
* we will catch possible errors. */
|
||||||
* catch possible error. */
|
if ((fullPath = virFileCanonicalizePath(relPath ? relPath : path))) {
|
||||||
if ((fullPath = canonicalize_file_name(relPath ? relPath : path))) {
|
|
||||||
path = fullPath;
|
path = fullPath;
|
||||||
} else {
|
} else {
|
||||||
/* Yeah, our worst nightmares just became true. Path does
|
/* Yeah, our worst nightmares just became true. Path does
|
||||||
@ -148,7 +147,7 @@ checkPath(const char *path)
|
|||||||
|
|
||||||
virFileRemoveLastComponent(crippledPath);
|
virFileRemoveLastComponent(crippledPath);
|
||||||
|
|
||||||
if ((fullPath = canonicalize_file_name(crippledPath)))
|
if ((fullPath = virFileCanonicalizePath(crippledPath)))
|
||||||
path = fullPath;
|
path = fullPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user