Re: [PATCH 07/39] Remove virStorageFileCanonicalizePath

2021-04-07 Thread Ján Tomko

On a Thursday in 2021, Peter Krempa wrote:

Signed-off-by: Peter Krempa 
---
src/libvirt_private.syms  |   1 -
src/util/virstoragefile.c | 210 --
src/util/virstoragefile.h |   8 --
3 files changed, 219 deletions(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


[PATCH 07/39] Remove virStorageFileCanonicalizePath

2021-04-01 Thread Peter Krempa
Signed-off-by: Peter Krempa 
---
 src/libvirt_private.syms  |   1 -
 src/util/virstoragefile.c | 210 --
 src/util/virstoragefile.h |   8 --
 3 files changed, 219 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 62ccda467f..9208db2056 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3231,7 +3231,6 @@ virSocketAddrSetPort;


 # util/virstoragefile.h
-virStorageFileCanonicalizePath;
 virStorageFileGetNPIVKey;
 virStorageFileGetSCSIKey;
 virStorageFileParseBackingStoreStr;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 9df891b57c..e6bc723d1e 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -214,213 +214,3 @@ virStorageFileParseBackingStoreStr(const char *str,
 *chainIndex = idx;
 return 0;
 }
-
-
-static char *
-virStorageFileCanonicalizeFormatPath(char **components,
- size_t ncomponents,
- bool beginSlash,
- bool beginDoubleSlash)
-{
-g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-size_t i;
-char *ret = NULL;
-
-if (beginSlash)
-virBufferAddLit(, "/");
-
-if (beginDoubleSlash)
-virBufferAddLit(, "/");
-
-for (i = 0; i < ncomponents; i++) {
-if (i != 0)
-virBufferAddLit(, "/");
-
-virBufferAdd(, components[i], -1);
-}
-
-/* if the output string is empty just return an empty string */
-if (!(ret = virBufferContentAndReset()))
-ret = g_strdup("");
-
-return ret;
-}
-
-
-static int
-virStorageFileCanonicalizeInjectSymlink(const char *path,
-size_t at,
-char ***components,
-size_t *ncomponents)
-{
-char **tmp = NULL;
-char **next;
-size_t ntmp = 0;
-int ret = -1;
-
-if (!(tmp = virStringSplitCount(path, "/", 0, )))
-goto cleanup;
-
-/* prepend */
-for (next = tmp; *next; next++) {
-if (VIR_INSERT_ELEMENT(*components, at, *ncomponents, *next) < 0)
-goto cleanup;
-
-at++;
-}
-
-ret = 0;
-
- cleanup:
-virStringListFreeCount(tmp, ntmp);
-return ret;
-}
-
-
-char *
-virStorageFileCanonicalizePath(const char *path,
-   virStorageFileSimplifyPathReadlinkCallback cb,
-   void *cbdata)
-{
-GHashTable *cycle = NULL;
-bool beginSlash = false;
-bool beginDoubleSlash = false;
-char **components = NULL;
-size_t ncomponents = 0;
-size_t i = 0;
-size_t j = 0;
-int rc;
-char *ret = NULL;
-g_autofree char *linkpath = NULL;
-g_autofree char *currentpath = NULL;
-
-if (path[0] == '/') {
-beginSlash = true;
-
-if (path[1] == '/' && path[2] != '/')
-beginDoubleSlash = true;
-}
-
-if (!(cycle = virHashNew(NULL)))
-goto cleanup;
-
-if (!(components = virStringSplitCount(path, "/", 0, )))
-goto cleanup;
-
-j = 0;
-while (j < ncomponents) {
-/* skip slashes */
-if (STREQ(components[j], "")) {
-VIR_FREE(components[j]);
-VIR_DELETE_ELEMENT(components, j, ncomponents);
-continue;
-}
-j++;
-}
-
-while (i < ncomponents) {
-/* skip '.'s unless it's the last one remaining */
-if (STREQ(components[i], ".") &&
-(beginSlash || ncomponents  > 1)) {
-VIR_FREE(components[i]);
-VIR_DELETE_ELEMENT(components, i, ncomponents);
-continue;
-}
-
-/* resolve changes to parent directory */
-if (STREQ(components[i], "..")) {
-if (!beginSlash &&
-(i == 0 || STREQ(components[i - 1], ".."))) {
-i++;
-continue;
-}
-
-VIR_FREE(components[i]);
-VIR_DELETE_ELEMENT(components, i, ncomponents);
-
-if (i != 0) {
-VIR_FREE(components[i - 1]);
-VIR_DELETE_ELEMENT(components, i - 1, ncomponents);
-i--;
-}
-
-continue;
-}
-
-/* check if the actual path isn't resulting into a symlink */
-if (!(currentpath = virStorageFileCanonicalizeFormatPath(components,
- i + 1,
- beginSlash,
- 
beginDoubleSlash)))
-goto cleanup;
-
-if ((rc = cb(currentpath, , cbdata)) < 0)
-goto cleanup;
-
-if (rc == 0) {
-if (virHashLookup(cycle, currentpath)) {
-virReportSystemError(ELOOP,
- _("Failed to canonicalize path '%s'"), 
path);
-