]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Replace virFileAbsPath() with g_canonicalize_filename()
authorLuke Yue <lukedyue@gmail.com>
Mon, 7 Jun 2021 06:10:47 +0000 (14:10 +0800)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 15 Jun 2021 10:42:02 +0000 (12:42 +0200)
Signed-off-by: Luke Yue <lukedyue@gmail.com>
src/libvirt-domain.c
src/libvirt_private.syms
src/util/virfile.c
src/util/virfile.h
src/util/virlog.c

index 42c75f6cc573489c20db3dc49ef61dfa2ffa169b..750e32f0ca2c5a3c958c2ce4989b48bcc294ddbc 100644 (file)
@@ -827,7 +827,7 @@ virDomainSave(virDomainPtr domain, const char *to)
         char *absolute_to;
 
         /* We must absolutize the file path as the save is done out of process */
-        if (virFileAbsPath(to, &absolute_to) < 0) {
+        if (!(absolute_to = g_canonicalize_filename(to, NULL))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("could not build absolute output file path"));
             goto error;
@@ -915,7 +915,7 @@ virDomainSaveFlags(virDomainPtr domain, const char *to,
         char *absolute_to;
 
         /* We must absolutize the file path as the save is done out of process */
-        if (virFileAbsPath(to, &absolute_to) < 0) {
+        if (!(absolute_to = g_canonicalize_filename(to, NULL))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("could not build absolute output file path"));
             goto error;
@@ -965,7 +965,7 @@ virDomainRestore(virConnectPtr conn, const char *from)
         char *absolute_from;
 
         /* We must absolutize the file path as the restore is done out of process */
-        if (virFileAbsPath(from, &absolute_from) < 0) {
+        if (!(absolute_from = g_canonicalize_filename(from, NULL))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("could not build absolute input file path"));
             goto error;
@@ -1039,7 +1039,7 @@ virDomainRestoreFlags(virConnectPtr conn, const char *from, const char *dxml,
         char *absolute_from;
 
         /* We must absolutize the file path as the restore is done out of process */
-        if (virFileAbsPath(from, &absolute_from) < 0) {
+        if (!(absolute_from = g_canonicalize_filename(from, NULL))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("could not build absolute input file path"));
             goto error;
@@ -1097,7 +1097,7 @@ virDomainSaveImageGetXMLDesc(virConnectPtr conn, const char *file,
         char *absolute_file;
 
         /* We must absolutize the file path as the read is done out of process */
-        if (virFileAbsPath(file, &absolute_file) < 0) {
+        if (!(absolute_file = g_canonicalize_filename(file, NULL))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("could not build absolute input file path"));
             goto error;
@@ -1170,7 +1170,7 @@ virDomainSaveImageDefineXML(virConnectPtr conn, const char *file,
         char *absolute_file;
 
         /* We must absolutize the file path as the read is done out of process */
-        if (virFileAbsPath(file, &absolute_file) < 0) {
+        if (!(absolute_file = g_canonicalize_filename(file, NULL))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("could not build absolute input file path"));
             goto error;
@@ -1245,7 +1245,7 @@ virDomainCoreDump(virDomainPtr domain, const char *to, unsigned int flags)
         char *absolute_to;
 
         /* We must absolutize the file path as the save is done out of process */
-        if (virFileAbsPath(to, &absolute_to) < 0) {
+        if (!(absolute_to = g_canonicalize_filename(to, NULL))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("could not build absolute core file path"));
             goto error;
@@ -1329,7 +1329,7 @@ virDomainCoreDumpWithFormat(virDomainPtr domain, const char *to,
         char *absolute_to;
 
         /* We must absolutize the file path as the save is done out of process */
-        if (virFileAbsPath(to, &absolute_to) < 0) {
+        if (!(absolute_to = g_canonicalize_filename(to, NULL))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("could not build absolute core file path"));
             goto error;
index 8f0945f581b2e7eb2f3a83d5a8046dde656425f4..9a10015fe35855760b2e3349a981a0e94454211f 100644 (file)
@@ -2178,7 +2178,6 @@ virDirOpen;
 virDirOpenIfExists;
 virDirOpenQuiet;
 virDirRead;
-virFileAbsPath;
 virFileAccessibleAs;
 virFileActivateDirOverrideForLib;
 virFileActivateDirOverrideForProg;
index f32f3e37e44954e39e0446478700ad6172a004e8..d9d5b979f3bfd3eb12581aa81deb88d6cbf6ef8c 100644 (file)
@@ -1688,8 +1688,7 @@ virFindFileInPath(const char *file)
         if (!virFileIsExecutable(file))
             return NULL;
 
-        ignore_value(virFileAbsPath(file, &abspath));
-        return abspath;
+        return g_canonicalize_filename(file, NULL);
     }
 
     /* copy PATH env so we can tweak it */
@@ -3146,27 +3145,6 @@ virFileOpenTty(int *ttyprimary G_GNUC_UNUSED,
 }
 #endif /* WIN32 */
 
-/*
- * Creates an absolute path for a potentially relative path.
- * Return 0 if the path was not relative, or on success.
- * Return -1 on error.
- *
- * You must free the result.
- */
-int
-virFileAbsPath(const char *path, char **abspath)
-{
-    if (g_path_is_absolute(path)) {
-        *abspath = g_strdup(path);
-    } else {
-        g_autofree char *buf = g_get_current_dir();
-
-        *abspath = g_build_filename(buf, path, NULL);
-    }
-
-    return 0;
-}
-
 /* Remove spurious / characters from a path. The result must be freed */
 char *
 virFileSanitizePath(const char *path)
index b9f7b1766f9580b38e71d9b83a20f51c66a7efe7..72368495bf52914c4e119e74ad0db1dcd11fb968 100644 (file)
@@ -283,9 +283,6 @@ char *virFileBuildPath(const char *dir,
                        const char *name,
                        const char *ext) G_GNUC_WARN_UNUSED_RESULT;
 
-
-int virFileAbsPath(const char *path,
-                   char **abspath) G_GNUC_WARN_UNUSED_RESULT;
 void virFileRemoveLastComponent(char *path);
 
 int virFileOpenTty(int *ttymaster,
index 78be1993cd796a5a132cca7135dad4a3d2bd3fde..3ad043d98a1a3537aaf1d3d1a0dd2362bc71bb33 100644 (file)
@@ -1512,7 +1512,7 @@ virLogParseOutput(const char *src)
 #endif
         break;
     case VIR_LOG_TO_FILE:
-        if (virFileAbsPath(tokens[2], &abspath) < 0)
+        if (!(abspath = g_canonicalize_filename(tokens[2], NULL)))
             return NULL;
         ret = virLogNewOutputToFile(prio, abspath);
         VIR_FREE(abspath);