util: Rename virFileMatchesNameSuffix() to virStringMatchesNameSuffix()

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.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Andrea Bolognani 2019-03-06 15:45:15 +01:00
parent 9c5fa79fd7
commit b5cc0a7f29
7 changed files with 23 additions and 24 deletions

View File

@ -819,7 +819,7 @@ virSecretLoadValidateUUID(virSecretDefPtr def,
virUUIDFormat(def->uuid, uuidstr);
if (!virFileMatchesNameSuffix(file, uuidstr, ".xml")) {
if (!virStringMatchesNameSuffix(file, uuidstr, ".xml")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("<uuid> does not match secret file name '%s'"),
file);

View File

@ -1585,7 +1585,7 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools,
if (!(def = virStoragePoolDefParseFile(path)))
return NULL;
if (!virFileMatchesNameSuffix(file, def->name, ".xml")) {
if (!virStringMatchesNameSuffix(file, def->name, ".xml")) {
virReportError(VIR_ERR_XML_ERROR,
_("Storage pool config filename '%s' does "
"not match pool name '%s'"),

View File

@ -1859,7 +1859,6 @@ virFileLoopDeviceAssociate;
virFileMakeParentPath;
virFileMakePath;
virFileMakePathWithMode;
virFileMatchesNameSuffix;
virFileMoveMount;
virFileNBDDeviceAssociate;
virFileOpenAs;
@ -2980,6 +2979,7 @@ virStringListLength;
virStringListMerge;
virStringListRemove;
virStringMatch;
virStringMatchesNameSuffix;
virStringParsePort;
virStringReplace;
virStringSearch;

View File

@ -1508,23 +1508,6 @@ virFileWriteStr(const char *path, const char *str, mode_t mode)
return 0;
}
int
virFileMatchesNameSuffix(const char *file,
const char *name,
const char *suffix)
{
int filelen = strlen(file);
int namelen = strlen(name);
int suffixlen = strlen(suffix);
if (filelen == (namelen + suffixlen) &&
STREQLEN(file, name, namelen) &&
STREQLEN(file + namelen, suffix, suffixlen))
return 1;
else
return 0;
}
#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)

View File

@ -162,10 +162,6 @@ int virFileReadBufQuiet(const char *file, char *buf, int len)
int virFileWriteStr(const char *path, const char *str, mode_t mode)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
int virFileMatchesNameSuffix(const char *file,
const char *name,
const char *suffix);
int virFileLinkPointsTo(const char *checkLink,
const char *checkDest)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

View File

@ -1266,6 +1266,23 @@ virStringStripSuffix(char *str,
return 1;
}
int
virStringMatchesNameSuffix(const char *file,
const char *name,
const char *suffix)
{
int filelen = strlen(file);
int namelen = strlen(name);
int suffixlen = strlen(suffix);
if (filelen == (namelen + suffixlen) &&
STREQLEN(file, name, namelen) &&
STREQLEN(file + namelen, suffix, suffixlen))
return 1;
else
return 0;
}
/**
* virStringStripIPv6Brackets:
* @str: the string to strip

View File

@ -292,6 +292,9 @@ int virStringHasCaseSuffix(const char *str,
const char *suffix);
int virStringStripSuffix(char *str,
const char *suffix) ATTRIBUTE_RETURN_CHECK;
int virStringMatchesNameSuffix(const char *file,
const char *name,
const char *suffix);
void virStringStripIPv6Brackets(char *str);
bool virStringHasChars(const char *str,