[PATCH 1/2] Replace virFileAbsPath() with g_canonicalize_filename()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Luke Yue <lukedyue@xxxxxxxxx>
---
 src/libvirt-domain.c     | 16 ++++++++--------
 src/libvirt_private.syms |  1 -
 src/util/virfile.c       | 23 +----------------------
 src/util/virfile.h       |  3 ---
 src/util/virlog.c        |  2 +-
 5 files changed, 10 insertions(+), 35 deletions(-)

diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 42c75f6cc5..750e32f0ca 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -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;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0ced2a7990..e4b2d386f7 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2176,7 +2176,6 @@ virDirOpen;
 virDirOpenIfExists;
 virDirOpenQuiet;
 virDirRead;
-virFileAbsPath;
 virFileAccessibleAs;
 virFileActivateDirOverrideForLib;
 virFileActivateDirOverrideForProg;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index f32f3e37e4..7fe357ab16 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1688,7 +1688,7 @@ virFindFileInPath(const char *file)
         if (!virFileIsExecutable(file))
             return NULL;
 
-        ignore_value(virFileAbsPath(file, &abspath));
+        ignore_value(abspath = g_canonicalize_filename(file, NULL));
         return abspath;
     }
 
@@ -3146,27 +3146,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)
diff --git a/src/util/virfile.h b/src/util/virfile.h
index b9f7b1766f..72368495bf 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -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,
diff --git a/src/util/virlog.c b/src/util/virlog.c
index 78be1993cd..3ad043d98a 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -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);
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux