Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
12e75a52
Commit
12e75a52
authored
May 31, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
archive/ArchiveLookup: remove "suffix" output parameter
Let the caller do this. Our GetSuffix() function was broken anyway.
parent
508ba227
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
31 deletions
+15
-31
ArchiveLookup.cxx
src/archive/ArchiveLookup.cxx
+1
-16
ArchiveLookup.hxx
src/archive/ArchiveLookup.hxx
+3
-4
ArchiveInputPlugin.cxx
src/input/plugins/ArchiveInputPlugin.cxx
+4
-2
test_archive.cxx
test/test_archive.cxx
+7
-9
No files found.
src/archive/ArchiveLookup.cxx
View file @
12e75a52
...
@@ -36,21 +36,9 @@ FindSlash(char *p, size_t i) noexcept
...
@@ -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,
...
@@ -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
,
...
...
src/archive/ArchiveLookup.hxx
View file @
12e75a52
...
@@ -24,24 +24,23 @@
...
@@ -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
src/input/plugins/ArchiveInputPlugin.cxx
View file @
12e75a52
...
@@ -44,9 +44,9 @@ OpenArchiveInputStream(Path path, Mutex &mutex)
...
@@ -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)
...
@@ -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
)
{
...
...
test/test_archive.cxx
View file @
12e75a52
...
@@ -8,41 +8,39 @@
...
@@ -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
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment