[libvirt] [PATCHv3 17/36] util: storagefile: Add canonicalization to virStorageFileSimplifyPath

Eric Blake eblake at redhat.com
Tue Jun 3 01:13:44 UTC 2014


On 05/30/2014 02:37 AM, Peter Krempa wrote:
> The recently introduced virStorageFileSimplifyPath is good at resolving
> relative portions of a path. To add full path canonicalization
> capability we need to be able to resolve symlinks in the path too.
> 
> This patch adds a callback to that function so that arbitrary storage
> systems can use this functionality.
> ---
>  src/libvirt_private.syms  |  1 +
>  src/util/virstoragefile.c | 82 +++++++++++++++++++++++++++++++++++++++++++++--
>  src/util/virstoragefile.h |  9 ++++++
>  tests/virstoragetest.c    | 80 +++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 170 insertions(+), 2 deletions(-)
> 

> 
> diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
> index 80d73ca..771df0b 100644
> --- a/tests/virstoragetest.c
> +++ b/tests/virstoragetest.c
> @@ -639,6 +639,72 @@ testPathRelative(const void *args)
>  }
> 
> 
> +struct testPathCanonicalizeData
> +{
> +    const char *path;
> +    const char *expect;
> +};
> +
> +static const char *testPathCanonicalizeSymlinks[][2] =
> +{
> +    {"/path/blah", "/other/path/huzah"},
> +    {"/path/to/relative/symlink", "../../actual/file"},
> +};

Looks like a good way to test both types of symlinks.


> +
> +    TEST_PATH_CANONICALIZE(1, "/some/full/path", "/some/full/path");
> +    TEST_PATH_CANONICALIZE(2, "/path/blah", "/other/path/huzah");
> +    TEST_PATH_CANONICALIZE(3, "/path/to/relative/symlink", "/path/actual/file");
> +

You probably also want to test a symlink to directory in the middle of a
longer name: for example, /path/blah/yippee should resolve to
/other/path/huzah/yippee

>   cleanup:
>      /* Final cleanup */
>      virStorageSourceFree(chain);
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140602/a7a7ddef/attachment-0001.sig>


More information about the libvir-list mailing list