]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Rename virFileHasSuffix() to virStringHasCaseSuffix()
authorAndrea Bolognani <abologna@redhat.com>
Wed, 6 Mar 2019 14:07:26 +0000 (15:07 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Thu, 7 Mar 2019 09:08:47 +0000 (10:08 +0100)
Despite its name, this is really just a general-purpose string
manipulation function, so it should be moved to the virstring
module and renamed accordingly.

In addition to the obvious s/File/String/, also tweak the name
to make it clear that the presence of the suffix is verified
using case-insensitive comparison.

A few trivial whitespace changes are squashed in.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
15 files changed:
src/conf/virsecretobj.c
src/conf/virstorageobj.c
src/esx/esx_driver.c
src/esx/esx_storage_backend_vmfs.c
src/libvirt_private.syms
src/util/virfile.c
src/util/virfile.h
src/util/virstoragefile.c
src/util/virstring.c
src/util/virstring.h
src/vmware/vmware_conf.c
src/vmx/vmx.c
tests/testutils.c
tests/virschematest.c
tools/nss/libvirt_nss.c

index 8b418d5e66e4d5af65728aed7214da7cd9af66d1..5cd36b8a40ffd6b29db66b17cdb8b067d98446cb 100644 (file)
@@ -949,7 +949,7 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets,
         char *path;
         virSecretObjPtr obj;
 
-        if (!virFileHasSuffix(de->d_name, ".xml"))
+        if (!virStringHasCaseSuffix(de->d_name, ".xml"))
             continue;
 
         if (!(path = virFileBuildPath(configDir, de->d_name, NULL)))
index 2286857acf2a3c2a8513d4f09f2a0c41cbadc481..68c89bd9a9083f4cc8038b219a32347d91acc2ee 100644 (file)
@@ -1719,7 +1719,7 @@ virStoragePoolObjLoadAllConfigs(virStoragePoolObjListPtr pools,
         char *autostartLink;
         virStoragePoolObjPtr obj;
 
-        if (!virFileHasSuffix(entry->d_name, ".xml"))
+        if (!virStringHasCaseSuffix(entry->d_name, ".xml"))
             continue;
 
         if (!(path = virFileBuildPath(configDir, entry->d_name, NULL)))
index 379c2bae730a91c7f5cf3812e6bbf1f4a1e7243c..afebd785663bb49c1e87aeecf2eda42b212779b5 100644 (file)
@@ -3078,7 +3078,7 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
         goto cleanup;
     }
 
-    if (! virFileHasSuffix(src, ".vmdk")) {
+    if (!virStringHasCaseSuffix(src, ".vmdk")) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Expecting source '%s' of first file-based harddisk to "
                          "be a VMDK image"), src);
index 6d6bd1a6ceee6870461b4e3a8203a4d729b9f12b..c56f887c25a161a70af2f7f6fc0de522949408f2 100644 (file)
@@ -884,7 +884,7 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
         goto cleanup;
     }
 
-    if (! virFileHasSuffix(def->name, ".vmdk")) {
+    if (!virStringHasCaseSuffix(def->name, ".vmdk")) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Volume name '%s' has unsupported suffix, "
                          "expecting '.vmdk'"), def->name);
@@ -1104,7 +1104,7 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
         goto cleanup;
     }
 
-    if (! virFileHasSuffix(def->name, ".vmdk")) {
+    if (!virStringHasCaseSuffix(def->name, ".vmdk")) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Volume name '%s' has unsupported suffix, "
                          "expecting '.vmdk'"), def->name);
index 3ae48ad33add2c63e2e42735f7529b53f11f7424..9b4aee50d56724c431d66ef1fa568b25ab59fe24 100644 (file)
@@ -1842,7 +1842,6 @@ virFileGetHugepageSize;
 virFileGetMountReverseSubtree;
 virFileGetMountSubtree;
 virFileGetXAttr;
-virFileHasSuffix;
 virFileInData;
 virFileIsAbsPath;
 virFileIsCDROM;
@@ -2966,6 +2965,7 @@ virStrdup;
 virStringBufferIsPrintable;
 virStringEncodeBase64;
 virStringFilterChars;
+virStringHasCaseSuffix;
 virStringHasChars;
 virStringHasControlChars;
 virStringIsEmpty;
index 9208523c471deffa2b833cd291cb9d0dfdf518ef..21f7dc1ac39154782c103850716a19cb6770c000 100644 (file)
@@ -1543,19 +1543,6 @@ virFileMatchesNameSuffix(const char *file,
         return 0;
 }
 
-int
-virFileHasSuffix(const char *str,
-                 const char *suffix)
-{
-    int len = strlen(str);
-    int suffixlen = strlen(suffix);
-
-    if (len < suffixlen)
-        return 0;
-
-    return STRCASEEQ(str + len - suffixlen, suffix);
-}
-
 #define SAME_INODE(Stat_buf_1, Stat_buf_2) \
   ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
    && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
index 0b946fe1ca0d3eb4475741e696c8cfda0913a8b1..5a43d57181da862e7d50094b2f0e5f6948f57b53 100644 (file)
@@ -166,9 +166,6 @@ int virFileMatchesNameSuffix(const char *file,
                              const char *name,
                              const char *suffix);
 
-int virFileHasSuffix(const char *str,
-                     const char *suffix);
-
 int virFileStripSuffix(char *str,
                        const char *suffix) ATTRIBUTE_RETURN_CHECK;
 
index 233278e879f92e6138d5c4dab91367640a32868c..50ee9b574c344e96b86449c1295eb6b23a34e6ac 100644 (file)
@@ -725,7 +725,7 @@ virStorageFileMatchesExtension(const char *extension,
     if (extension == NULL)
         return false;
 
-    if (virFileHasSuffix(path, extension))
+    if (virStringHasCaseSuffix(path, extension))
         return true;
 
     return false;
index 8a791f96d4e993f6924a74e4c9508932feec8169..399b9468e643e30c66aa460a9cd52609f81926e0 100644 (file)
@@ -1235,6 +1235,18 @@ virStringReplace(const char *haystack,
     return virBufferContentAndReset(&buf);
 }
 
+int
+virStringHasCaseSuffix(const char *str,
+                       const char *suffix)
+{
+    int len = strlen(str);
+    int suffixlen = strlen(suffix);
+
+    if (len < suffixlen)
+        return 0;
+
+    return STRCASEEQ(str + len - suffixlen, suffix);
+}
 
 /**
  * virStringStripIPv6Brackets:
index f2e72936c84804de4b1ad4c46490ec3e2cad16bf..b2ba97a8d18fd1dd764ef78e6b343395c0b4269a 100644 (file)
@@ -288,6 +288,9 @@ char *virStringReplace(const char *haystack,
                        const char *newneedle)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
 
+int virStringHasCaseSuffix(const char *str,
+                           const char *suffix);
+
 void virStringStripIPv6Brackets(char *str);
 bool virStringHasChars(const char *str,
                        const char *chars);
index 21559da4a4fc9f6febbe62df3d23cef5f6c6e4d6..0c1b1f9550536f5c0c751b67226841937da77ad3 100644 (file)
@@ -434,7 +434,7 @@ vmwareVmxPath(virDomainDefPtr vmdef, char **vmxPath)
     if (vmwareParsePath(src, &directoryName, &fileName) < 0)
         goto cleanup;
 
-    if (!virFileHasSuffix(fileName, ".vmdk")) {
+    if (!virStringHasCaseSuffix(fileName, ".vmdk")) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Expecting source '%s' of first file-based harddisk "
                          "to be a VMDK image"), src);
index 75cdea9067995ccd3ed6ef5b9b0cd497d54277a7..bbf8e55c3fa5ae09d52608c0c380614ba4dcf755 100644 (file)
@@ -1600,7 +1600,7 @@ virVMXParseConfig(virVMXContext *ctx,
     if (virVMXGetConfigString(conf, "guestOS", &guestOS, true) < 0)
         goto cleanup;
 
-    if (guestOS != NULL && virFileHasSuffix(guestOS, "-64")) {
+    if (guestOS != NULL && virStringHasCaseSuffix(guestOS, "-64")) {
         def->os.arch = VIR_ARCH_X86_64;
     } else {
         def->os.arch = VIR_ARCH_I686;
@@ -2218,7 +2218,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
 
     /* Setup virDomainDiskDef */
     if (device == VIR_DOMAIN_DISK_DEVICE_DISK) {
-        if (virFileHasSuffix(fileName, ".vmdk")) {
+        if (virStringHasCaseSuffix(fileName, ".vmdk")) {
             char *tmp;
 
             if (deviceType != NULL) {
@@ -2254,7 +2254,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
             if (mode)
                 (*def)->transient = STRCASEEQ(mode,
                                               "independent-nonpersistent");
-        } else if (virFileHasSuffix(fileName, ".iso") ||
+        } else if (virStringHasCaseSuffix(fileName, ".iso") ||
                    STREQ(fileName, "emptyBackingString") ||
                    (deviceType &&
                     (STRCASEEQ(deviceType, "atapi-cdrom") ||
@@ -2277,7 +2277,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
             goto cleanup;
         }
     } else if (device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
-        if (virFileHasSuffix(fileName, ".iso")) {
+        if (virStringHasCaseSuffix(fileName, ".iso")) {
             char *tmp;
 
             if (deviceType && STRCASENEQ(deviceType, "cdrom-image")) {
@@ -2295,7 +2295,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
                 goto cleanup;
             }
             VIR_FREE(tmp);
-        } else if (virFileHasSuffix(fileName, ".vmdk")) {
+        } else if (virStringHasCaseSuffix(fileName, ".vmdk")) {
             /*
              * This function was called in order to parse a CDROM device, but
              * .vmdk files are for harddisk devices only. Just ignore it,
@@ -3585,7 +3585,7 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def,
         const char *src = virDomainDiskGetSource(def);
 
         if (src) {
-            if (!virFileHasSuffix(src, fileExt)) {
+            if (!virStringHasCaseSuffix(src, fileExt)) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Image file for %s %s '%s' has "
                                  "unsupported suffix, expecting '%s'"),
index 13bb9630dfd8e7b5c30883bf3a94f0af120d3ae1..cfdf122ae00b50c00917b26cec6dff9e5dec3e35 100644 (file)
@@ -525,8 +525,8 @@ virTestRewrapFile(const char *filename)
     char *script = NULL;
     virCommandPtr cmd = NULL;
 
-    if (!(virFileHasSuffix(filename, ".args") ||
-          virFileHasSuffix(filename, ".ldargs")))
+    if (!(virStringHasCaseSuffix(filename, ".args") ||
+          virStringHasCaseSuffix(filename, ".ldargs")))
         return 0;
 
     if (!perl) {
index a89a26b9181846823b0c0dfb14c9c5784c34103d..5ef61e3056c6acb049fab8072c42f4cb3c65e484 100644 (file)
@@ -41,7 +41,7 @@ static int
 testSchemaFile(const void *args)
 {
     const struct testSchemaData *data = args;
-    bool shouldFail = virFileHasSuffix(data->xml_path, "-invalid.xml");
+    bool shouldFail = virStringHasCaseSuffix(data->xml_path, "-invalid.xml");
     xmlDocPtr xml = NULL;
     int ret = -1;
 
@@ -82,7 +82,7 @@ testSchemaDir(const char *schema,
         return -1;
 
     while ((rc = virDirRead(dir, &ent, dir_path)) > 0) {
-        if (!virFileHasSuffix(ent->d_name, ".xml"))
+        if (!virStringHasCaseSuffix(ent->d_name, ".xml"))
             continue;
         if (ent->d_name[0] == '.')
             continue;
index 46d051c08cde34aad54e0d2cb3824b8ced4a9f3e..4d86f8e6ce86665da3bbdd33e9f8883841b3055c 100644 (file)
@@ -274,7 +274,7 @@ findLease(const char *name,
     while ((ret = virDirRead(dir, &entry, leaseDir)) > 0) {
         char *path;
 
-        if (virFileHasSuffix(entry->d_name, ".status")) {
+        if (virStringHasCaseSuffix(entry->d_name, ".status")) {
             if (!(path = virFileBuildPath(leaseDir, entry->d_name, NULL)))
                 goto cleanup;
 
@@ -285,7 +285,7 @@ findLease(const char *name,
                 goto cleanup;
             }
             VIR_FREE(path);
-        } else if (virFileHasSuffix(entry->d_name, ".macs")) {
+        } else if (virStringHasCaseSuffix(entry->d_name, ".macs")) {
             if (!(path = virFileBuildPath(leaseDir, entry->d_name, NULL)))
                 goto cleanup;