提交 2de7dcba 编写于 作者: A Andrea Bolognani

util: Rename virFileHasSuffix() to virStringHasCaseSuffix()

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: NAndrea Bolognani <abologna@redhat.com>
ACKed-by: NPeter Krempa <pkrempa@redhat.com>
上级 ab2e9000
...@@ -949,7 +949,7 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets, ...@@ -949,7 +949,7 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets,
char *path; char *path;
virSecretObjPtr obj; virSecretObjPtr obj;
if (!virFileHasSuffix(de->d_name, ".xml")) if (!virStringHasCaseSuffix(de->d_name, ".xml"))
continue; continue;
if (!(path = virFileBuildPath(configDir, de->d_name, NULL))) if (!(path = virFileBuildPath(configDir, de->d_name, NULL)))
......
...@@ -1719,7 +1719,7 @@ virStoragePoolObjLoadAllConfigs(virStoragePoolObjListPtr pools, ...@@ -1719,7 +1719,7 @@ virStoragePoolObjLoadAllConfigs(virStoragePoolObjListPtr pools,
char *autostartLink; char *autostartLink;
virStoragePoolObjPtr obj; virStoragePoolObjPtr obj;
if (!virFileHasSuffix(entry->d_name, ".xml")) if (!virStringHasCaseSuffix(entry->d_name, ".xml"))
continue; continue;
if (!(path = virFileBuildPath(configDir, entry->d_name, NULL))) if (!(path = virFileBuildPath(configDir, entry->d_name, NULL)))
......
...@@ -3078,7 +3078,7 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) ...@@ -3078,7 +3078,7 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
goto cleanup; goto cleanup;
} }
if (! virFileHasSuffix(src, ".vmdk")) { if (!virStringHasCaseSuffix(src, ".vmdk")) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Expecting source '%s' of first file-based harddisk to " _("Expecting source '%s' of first file-based harddisk to "
"be a VMDK image"), src); "be a VMDK image"), src);
......
...@@ -884,7 +884,7 @@ esxStorageVolCreateXML(virStoragePoolPtr pool, ...@@ -884,7 +884,7 @@ esxStorageVolCreateXML(virStoragePoolPtr pool,
goto cleanup; goto cleanup;
} }
if (! virFileHasSuffix(def->name, ".vmdk")) { if (!virStringHasCaseSuffix(def->name, ".vmdk")) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Volume name '%s' has unsupported suffix, " _("Volume name '%s' has unsupported suffix, "
"expecting '.vmdk'"), def->name); "expecting '.vmdk'"), def->name);
...@@ -1104,7 +1104,7 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, ...@@ -1104,7 +1104,7 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool,
goto cleanup; goto cleanup;
} }
if (! virFileHasSuffix(def->name, ".vmdk")) { if (!virStringHasCaseSuffix(def->name, ".vmdk")) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Volume name '%s' has unsupported suffix, " _("Volume name '%s' has unsupported suffix, "
"expecting '.vmdk'"), def->name); "expecting '.vmdk'"), def->name);
......
...@@ -1842,7 +1842,6 @@ virFileGetHugepageSize; ...@@ -1842,7 +1842,6 @@ virFileGetHugepageSize;
virFileGetMountReverseSubtree; virFileGetMountReverseSubtree;
virFileGetMountSubtree; virFileGetMountSubtree;
virFileGetXAttr; virFileGetXAttr;
virFileHasSuffix;
virFileInData; virFileInData;
virFileIsAbsPath; virFileIsAbsPath;
virFileIsCDROM; virFileIsCDROM;
...@@ -2966,6 +2965,7 @@ virStrdup; ...@@ -2966,6 +2965,7 @@ virStrdup;
virStringBufferIsPrintable; virStringBufferIsPrintable;
virStringEncodeBase64; virStringEncodeBase64;
virStringFilterChars; virStringFilterChars;
virStringHasCaseSuffix;
virStringHasChars; virStringHasChars;
virStringHasControlChars; virStringHasControlChars;
virStringIsEmpty; virStringIsEmpty;
......
...@@ -1543,19 +1543,6 @@ virFileMatchesNameSuffix(const char *file, ...@@ -1543,19 +1543,6 @@ virFileMatchesNameSuffix(const char *file,
return 0; 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) \ #define SAME_INODE(Stat_buf_1, Stat_buf_2) \
((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \ ((Stat_buf_1).st_ino == (Stat_buf_2).st_ino \
&& (Stat_buf_1).st_dev == (Stat_buf_2).st_dev) && (Stat_buf_1).st_dev == (Stat_buf_2).st_dev)
......
...@@ -166,9 +166,6 @@ int virFileMatchesNameSuffix(const char *file, ...@@ -166,9 +166,6 @@ int virFileMatchesNameSuffix(const char *file,
const char *name, const char *name,
const char *suffix); const char *suffix);
int virFileHasSuffix(const char *str,
const char *suffix);
int virFileStripSuffix(char *str, int virFileStripSuffix(char *str,
const char *suffix) ATTRIBUTE_RETURN_CHECK; const char *suffix) ATTRIBUTE_RETURN_CHECK;
......
...@@ -725,7 +725,7 @@ virStorageFileMatchesExtension(const char *extension, ...@@ -725,7 +725,7 @@ virStorageFileMatchesExtension(const char *extension,
if (extension == NULL) if (extension == NULL)
return false; return false;
if (virFileHasSuffix(path, extension)) if (virStringHasCaseSuffix(path, extension))
return true; return true;
return false; return false;
......
...@@ -1235,6 +1235,18 @@ virStringReplace(const char *haystack, ...@@ -1235,6 +1235,18 @@ virStringReplace(const char *haystack,
return virBufferContentAndReset(&buf); 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: * virStringStripIPv6Brackets:
......
...@@ -288,6 +288,9 @@ char *virStringReplace(const char *haystack, ...@@ -288,6 +288,9 @@ char *virStringReplace(const char *haystack,
const char *newneedle) const char *newneedle)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
int virStringHasCaseSuffix(const char *str,
const char *suffix);
void virStringStripIPv6Brackets(char *str); void virStringStripIPv6Brackets(char *str);
bool virStringHasChars(const char *str, bool virStringHasChars(const char *str,
const char *chars); const char *chars);
......
...@@ -434,7 +434,7 @@ vmwareVmxPath(virDomainDefPtr vmdef, char **vmxPath) ...@@ -434,7 +434,7 @@ vmwareVmxPath(virDomainDefPtr vmdef, char **vmxPath)
if (vmwareParsePath(src, &directoryName, &fileName) < 0) if (vmwareParsePath(src, &directoryName, &fileName) < 0)
goto cleanup; goto cleanup;
if (!virFileHasSuffix(fileName, ".vmdk")) { if (!virStringHasCaseSuffix(fileName, ".vmdk")) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Expecting source '%s' of first file-based harddisk " _("Expecting source '%s' of first file-based harddisk "
"to be a VMDK image"), src); "to be a VMDK image"), src);
......
...@@ -1600,7 +1600,7 @@ virVMXParseConfig(virVMXContext *ctx, ...@@ -1600,7 +1600,7 @@ virVMXParseConfig(virVMXContext *ctx,
if (virVMXGetConfigString(conf, "guestOS", &guestOS, true) < 0) if (virVMXGetConfigString(conf, "guestOS", &guestOS, true) < 0)
goto cleanup; goto cleanup;
if (guestOS != NULL && virFileHasSuffix(guestOS, "-64")) { if (guestOS != NULL && virStringHasCaseSuffix(guestOS, "-64")) {
def->os.arch = VIR_ARCH_X86_64; def->os.arch = VIR_ARCH_X86_64;
} else { } else {
def->os.arch = VIR_ARCH_I686; def->os.arch = VIR_ARCH_I686;
...@@ -2218,7 +2218,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con ...@@ -2218,7 +2218,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
/* Setup virDomainDiskDef */ /* Setup virDomainDiskDef */
if (device == VIR_DOMAIN_DISK_DEVICE_DISK) { if (device == VIR_DOMAIN_DISK_DEVICE_DISK) {
if (virFileHasSuffix(fileName, ".vmdk")) { if (virStringHasCaseSuffix(fileName, ".vmdk")) {
char *tmp; char *tmp;
if (deviceType != NULL) { if (deviceType != NULL) {
...@@ -2254,7 +2254,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con ...@@ -2254,7 +2254,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
if (mode) if (mode)
(*def)->transient = STRCASEEQ(mode, (*def)->transient = STRCASEEQ(mode,
"independent-nonpersistent"); "independent-nonpersistent");
} else if (virFileHasSuffix(fileName, ".iso") || } else if (virStringHasCaseSuffix(fileName, ".iso") ||
STREQ(fileName, "emptyBackingString") || STREQ(fileName, "emptyBackingString") ||
(deviceType && (deviceType &&
(STRCASEEQ(deviceType, "atapi-cdrom") || (STRCASEEQ(deviceType, "atapi-cdrom") ||
...@@ -2277,7 +2277,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con ...@@ -2277,7 +2277,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
goto cleanup; goto cleanup;
} }
} else if (device == VIR_DOMAIN_DISK_DEVICE_CDROM) { } else if (device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
if (virFileHasSuffix(fileName, ".iso")) { if (virStringHasCaseSuffix(fileName, ".iso")) {
char *tmp; char *tmp;
if (deviceType && STRCASENEQ(deviceType, "cdrom-image")) { if (deviceType && STRCASENEQ(deviceType, "cdrom-image")) {
...@@ -2295,7 +2295,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con ...@@ -2295,7 +2295,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
goto cleanup; goto cleanup;
} }
VIR_FREE(tmp); 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 * This function was called in order to parse a CDROM device, but
* .vmdk files are for harddisk devices only. Just ignore it, * .vmdk files are for harddisk devices only. Just ignore it,
...@@ -3585,7 +3585,7 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def, ...@@ -3585,7 +3585,7 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def,
const char *src = virDomainDiskGetSource(def); const char *src = virDomainDiskGetSource(def);
if (src) { if (src) {
if (!virFileHasSuffix(src, fileExt)) { if (!virStringHasCaseSuffix(src, fileExt)) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Image file for %s %s '%s' has " _("Image file for %s %s '%s' has "
"unsupported suffix, expecting '%s'"), "unsupported suffix, expecting '%s'"),
......
...@@ -525,8 +525,8 @@ virTestRewrapFile(const char *filename) ...@@ -525,8 +525,8 @@ virTestRewrapFile(const char *filename)
char *script = NULL; char *script = NULL;
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
if (!(virFileHasSuffix(filename, ".args") || if (!(virStringHasCaseSuffix(filename, ".args") ||
virFileHasSuffix(filename, ".ldargs"))) virStringHasCaseSuffix(filename, ".ldargs")))
return 0; return 0;
if (!perl) { if (!perl) {
......
...@@ -41,7 +41,7 @@ static int ...@@ -41,7 +41,7 @@ static int
testSchemaFile(const void *args) testSchemaFile(const void *args)
{ {
const struct testSchemaData *data = 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; xmlDocPtr xml = NULL;
int ret = -1; int ret = -1;
...@@ -82,7 +82,7 @@ testSchemaDir(const char *schema, ...@@ -82,7 +82,7 @@ testSchemaDir(const char *schema,
return -1; return -1;
while ((rc = virDirRead(dir, &ent, dir_path)) > 0) { while ((rc = virDirRead(dir, &ent, dir_path)) > 0) {
if (!virFileHasSuffix(ent->d_name, ".xml")) if (!virStringHasCaseSuffix(ent->d_name, ".xml"))
continue; continue;
if (ent->d_name[0] == '.') if (ent->d_name[0] == '.')
continue; continue;
......
...@@ -274,7 +274,7 @@ findLease(const char *name, ...@@ -274,7 +274,7 @@ findLease(const char *name,
while ((ret = virDirRead(dir, &entry, leaseDir)) > 0) { while ((ret = virDirRead(dir, &entry, leaseDir)) > 0) {
char *path; char *path;
if (virFileHasSuffix(entry->d_name, ".status")) { if (virStringHasCaseSuffix(entry->d_name, ".status")) {
if (!(path = virFileBuildPath(leaseDir, entry->d_name, NULL))) if (!(path = virFileBuildPath(leaseDir, entry->d_name, NULL)))
goto cleanup; goto cleanup;
...@@ -285,7 +285,7 @@ findLease(const char *name, ...@@ -285,7 +285,7 @@ findLease(const char *name,
goto cleanup; goto cleanup;
} }
VIR_FREE(path); 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))) if (!(path = virFileBuildPath(leaseDir, entry->d_name, NULL)))
goto cleanup; goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册