archive/ArchiveLookup: remove "suffix" output parameter
Let the caller do this. Our GetSuffix() function was broken anyway.
This commit is contained in:
parent
508ba22789
commit
12e75a523a
@ -36,21 +36,9 @@ FindSlash(char *p, size_t i) noexcept
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
gcc_pure
|
|
||||||
static const char *
|
|
||||||
FindSuffix(const char *p, const char *i) noexcept
|
|
||||||
{
|
|
||||||
for (; i > p; --i) {
|
|
||||||
if (*i == '.')
|
|
||||||
return i + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
archive_lookup(char *pathname, const char **archive,
|
archive_lookup(char *pathname, const char **archive,
|
||||||
const char **inpath, const char **suffix)
|
const char **inpath)
|
||||||
{
|
{
|
||||||
size_t idx = strlen(pathname);
|
size_t idx = strlen(pathname);
|
||||||
|
|
||||||
@ -70,9 +58,6 @@ archive_lookup(char *pathname, const char **archive,
|
|||||||
//so the upper should be file
|
//so the upper should be file
|
||||||
*archive = pathname;
|
*archive = pathname;
|
||||||
*inpath = slash + 1;
|
*inpath = slash + 1;
|
||||||
|
|
||||||
//try to get suffix
|
|
||||||
*suffix = FindSuffix(pathname, slash - 1);
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
FormatError(archive_domain,
|
FormatError(archive_domain,
|
||||||
|
@ -24,24 +24,23 @@
|
|||||||
*
|
*
|
||||||
* archive_lookup is used to determine if part of pathname refers to an regular
|
* archive_lookup is used to determine if part of pathname refers to an regular
|
||||||
* file (archive). If so then its also used to split pathname into archive file
|
* file (archive). If so then its also used to split pathname into archive file
|
||||||
* and path used to locate file in archive. It also returns suffix of the file.
|
* and path used to locate file in archive.
|
||||||
* How it works:
|
* How it works:
|
||||||
* We do stat of the parent of input pathname as long as we find an regular file
|
* We do stat of the parent of input pathname as long as we find an regular file
|
||||||
* Normally this should never happen. When routine returns true pathname modified
|
* Normally this should never happen. When routine returns true pathname modified
|
||||||
* and split into archive, inpath and suffix. Otherwise nothing happens
|
* and split into archive and inpath. Otherwise nothing happens
|
||||||
*
|
*
|
||||||
* For example:
|
* For example:
|
||||||
*
|
*
|
||||||
* /music/path/Talco.zip/Talco - Combat Circus/12 - A la pachenka.mp3
|
* /music/path/Talco.zip/Talco - Combat Circus/12 - A la pachenka.mp3
|
||||||
* is split into archive: /music/path/Talco.zip
|
* is split into archive: /music/path/Talco.zip
|
||||||
* inarchive pathname: Talco - Combat Circus/12 - A la pachenka.mp3
|
* inarchive pathname: Talco - Combat Circus/12 - A la pachenka.mp3
|
||||||
* and suffix: zip
|
|
||||||
*
|
*
|
||||||
* Throws on error.
|
* Throws on error.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
archive_lookup(char *pathname, const char **archive,
|
archive_lookup(char *pathname, const char **archive,
|
||||||
const char **inpath, const char **suffix);
|
const char **inpath);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -44,9 +44,9 @@ OpenArchiveInputStream(Path path, Mutex &mutex)
|
|||||||
};
|
};
|
||||||
|
|
||||||
// archive_lookup will modify pname when true is returned
|
// archive_lookup will modify pname when true is returned
|
||||||
const char *archive, *filename, *suffix;
|
const char *archive, *filename;
|
||||||
try {
|
try {
|
||||||
if (!archive_lookup(pname, &archive, &filename, &suffix)) {
|
if (!archive_lookup(pname, &archive, &filename)) {
|
||||||
FormatDebug(archive_domain,
|
FormatDebug(archive_domain,
|
||||||
"not an archive, lookup %s failed", pname);
|
"not an archive, lookup %s failed", pname);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -57,6 +57,8 @@ OpenArchiveInputStream(Path path, Mutex &mutex)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *suffix = Path::FromFS(archive).GetSuffix();
|
||||||
|
|
||||||
//check which archive plugin to use (by ext)
|
//check which archive plugin to use (by ext)
|
||||||
arplug = archive_plugin_from_suffix(suffix);
|
arplug = archive_plugin_from_suffix(suffix);
|
||||||
if (!arplug) {
|
if (!arplug) {
|
||||||
|
@ -8,41 +8,39 @@
|
|||||||
|
|
||||||
TEST(ArchiveTest, Lookup)
|
TEST(ArchiveTest, Lookup)
|
||||||
{
|
{
|
||||||
const char *archive, *inpath, *suffix;
|
const char *archive, *inpath;
|
||||||
|
|
||||||
char *path = strdup("");
|
char *path = strdup("");
|
||||||
EXPECT_THROW(archive_lookup(path, &archive, &inpath, &suffix),
|
EXPECT_THROW(archive_lookup(path, &archive, &inpath),
|
||||||
std::system_error);
|
std::system_error);
|
||||||
free(path);
|
free(path);
|
||||||
|
|
||||||
path = strdup(".");
|
path = strdup(".");
|
||||||
EXPECT_FALSE(archive_lookup(path, &archive, &inpath, &suffix));
|
EXPECT_FALSE(archive_lookup(path, &archive, &inpath));
|
||||||
free(path);
|
free(path);
|
||||||
|
|
||||||
path = strdup("config.h");
|
path = strdup("config.h");
|
||||||
EXPECT_FALSE(archive_lookup(path, &archive, &inpath, &suffix));
|
EXPECT_FALSE(archive_lookup(path, &archive, &inpath));
|
||||||
free(path);
|
free(path);
|
||||||
|
|
||||||
path = strdup("src/foo/bar");
|
path = strdup("src/foo/bar");
|
||||||
EXPECT_THROW(archive_lookup(path, &archive, &inpath, &suffix),
|
EXPECT_THROW(archive_lookup(path, &archive, &inpath),
|
||||||
std::system_error);
|
std::system_error);
|
||||||
free(path);
|
free(path);
|
||||||
|
|
||||||
fclose(fopen("dummy", "w"));
|
fclose(fopen("dummy", "w"));
|
||||||
|
|
||||||
path = strdup("dummy/foo/bar");
|
path = strdup("dummy/foo/bar");
|
||||||
EXPECT_TRUE(archive_lookup(path, &archive, &inpath, &suffix));
|
EXPECT_TRUE(archive_lookup(path, &archive, &inpath));
|
||||||
EXPECT_EQ((const char *)path, archive);
|
EXPECT_EQ((const char *)path, archive);
|
||||||
EXPECT_STREQ(archive, "dummy");
|
EXPECT_STREQ(archive, "dummy");
|
||||||
EXPECT_STREQ(inpath, "foo/bar");
|
EXPECT_STREQ(inpath, "foo/bar");
|
||||||
EXPECT_EQ((const char *)nullptr, suffix);
|
|
||||||
free(path);
|
free(path);
|
||||||
|
|
||||||
path = strdup("config.h/foo/bar");
|
path = strdup("config.h/foo/bar");
|
||||||
EXPECT_TRUE(archive_lookup(path, &archive, &inpath, &suffix));
|
EXPECT_TRUE(archive_lookup(path, &archive, &inpath));
|
||||||
EXPECT_EQ((const char *)path, archive);
|
EXPECT_EQ((const char *)path, archive);
|
||||||
EXPECT_STREQ(archive, "config.h");
|
EXPECT_STREQ(archive, "config.h");
|
||||||
EXPECT_STREQ(inpath, "foo/bar");
|
EXPECT_STREQ(inpath, "foo/bar");
|
||||||
EXPECT_STREQ(suffix, "h");
|
|
||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user