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

Martin Kletzander mkletzan at redhat.com
Tue Jun 15 06:50:11 UTC 2021


On Mon, Jun 07, 2021 at 02:10:47PM +0800, Luke Yue wrote:
>Signed-off-by: Luke Yue <lukedyue at gmail.com>
>---
> 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))) {

I must say I'm not a fan of this "over-encapsulation" and I prefer the
more-readable:

     var = func(args);
     if (!var) {
     ...

but I know this is very subjective *and* we do not have a rule for it
*and* if we had a rule it would be based on other contributors'
preferences which I think actually prefer the way you did it.  So this
is fine, just a tiny rant to make me feel better ;)

[...]

>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;

ignore_value here does not make sense after the change.  And if you look
at it, you can just return the result of g_canonicalize_filename() here
directly.

Reviewed-by: Martin Kletzander <mkletzan at redhat.com>

I'll fix up this one and push it later.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20210615/d24366fb/attachment-0001.sig>


More information about the libvir-list mailing list