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
be79b44d
Commit
be79b44d
authored
Jun 15, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
archive/Lookup: pass const pointer
parent
17f207ff
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
35 deletions
+16
-35
ArchiveLookup.cxx
src/archive/ArchiveLookup.cxx
+7
-6
ArchiveLookup.hxx
src/archive/ArchiveLookup.hxx
+1
-1
ArchiveInputPlugin.cxx
src/input/plugins/ArchiveInputPlugin.cxx
+2
-10
test_archive.cxx
test/test_archive.cxx
+6
-18
No files found.
src/archive/ArchiveLookup.cxx
View file @
be79b44d
...
...
@@ -35,16 +35,17 @@ FindSlash(PathTraitsFS::pointer_type p, size_t i) noexcept
}
ArchiveLookupResult
archive_lookup
(
PathTraitsFS
::
pointer_type
pathname
)
archive_lookup
(
PathTraitsFS
::
const_
pointer_type
pathname
)
{
size_t
idx
=
strlen
(
pathname
);
PathTraitsFS
::
string
buffer
(
pathname
);
size_t
idx
=
buffer
.
size
();
PathTraitsFS
::
pointer_type
slash
=
nullptr
;
while
(
true
)
{
try
{
//try to stat if its real directory
const
FileInfo
file_info
(
Path
::
FromFS
(
pathname
));
const
FileInfo
file_info
(
Path
::
FromFS
(
buffer
.
c_str
()
));
//is something found ins original path (is not an archive)
if
(
slash
==
nullptr
)
...
...
@@ -53,7 +54,7 @@ archive_lookup(PathTraitsFS::pointer_type pathname)
//its a file ?
if
(
file_info
.
IsRegular
())
{
//so the upper should be file
return
{
AllocatedPath
::
FromFS
(
pathname
),
AllocatedPath
::
FromFS
(
slash
+
1
)};
return
{
AllocatedPath
::
FromFS
(
buffer
.
c_str
()
),
AllocatedPath
::
FromFS
(
slash
+
1
)};
}
else
{
return
{};
}
...
...
@@ -66,12 +67,12 @@ archive_lookup(PathTraitsFS::pointer_type pathname)
if
(
slash
!=
nullptr
)
*
slash
=
'/'
;
slash
=
FindSlash
(
pathname
,
idx
-
1
);
slash
=
FindSlash
(
&
buffer
.
front
()
,
idx
-
1
);
if
(
slash
==
nullptr
)
return
{};
*
slash
=
0
;
idx
=
slash
-
pathname
;
idx
=
slash
-
buffer
.
c_str
()
;
}
}
src/archive/ArchiveLookup.hxx
View file @
be79b44d
...
...
@@ -50,7 +50,7 @@ struct ArchiveLookupResult {
* Throws on error.
*/
ArchiveLookupResult
archive_lookup
(
PathTraitsFS
::
pointer_type
pathname
);
archive_lookup
(
PathTraitsFS
::
const_
pointer_type
pathname
);
#endif
src/input/plugins/ArchiveInputPlugin.cxx
View file @
be79b44d
...
...
@@ -25,30 +25,22 @@
#include "../InputStream.hxx"
#include "fs/Path.hxx"
#include "Log.hxx"
#include "util/ScopeExit.hxx"
#include <string.h>
InputStreamPtr
OpenArchiveInputStream
(
Path
path
,
Mutex
&
mutex
)
{
const
ArchivePlugin
*
arplug
;
char
*
pname
=
strdup
(
path
.
c_str
());
AtScopeExit
(
pname
)
{
free
(
pname
);
};
// archive_lookup will modify pname when true is returned
ArchiveLookupResult
l
;
try
{
l
=
archive_lookup
(
p
name
);
l
=
archive_lookup
(
p
ath
.
c_str
()
);
if
(
l
.
archive
.
IsNull
())
{
return
nullptr
;
}
}
catch
(...)
{
LogFormat
(
LogLevel
::
DEBUG
,
std
::
current_exception
(),
"not an archive, lookup %s failed"
,
p
name
);
"not an archive, lookup %s failed"
,
p
ath
.
c_str
()
);
return
nullptr
;
}
...
...
test/test_archive.cxx
View file @
be79b44d
...
...
@@ -8,35 +8,23 @@
TEST
(
ArchiveTest
,
Lookup
)
{
char
*
path
=
strdup
(
""
);
EXPECT_THROW
(
archive_lookup
(
path
),
std
::
system_error
);
free
(
path
);
EXPECT_THROW
(
archive_lookup
(
""
),
std
::
system_error
);
path
=
strdup
(
"."
);
EXPECT_FALSE
(
archive_lookup
(
path
));
free
(
path
);
EXPECT_FALSE
(
archive_lookup
(
"."
));
path
=
strdup
(
"config.h"
);
EXPECT_FALSE
(
archive_lookup
(
path
));
free
(
path
);
EXPECT_FALSE
(
archive_lookup
(
"config.h"
));
path
=
strdup
(
"src/foo/bar"
);
EXPECT_THROW
(
archive_lookup
(
path
),
std
::
system_error
);
free
(
path
);
EXPECT_THROW
(
archive_lookup
(
"src/foo/bar"
),
std
::
system_error
);
fclose
(
fopen
(
"dummy"
,
"w"
));
path
=
strdup
(
"dummy/foo/bar"
);
auto
result
=
archive_lookup
(
path
);
auto
result
=
archive_lookup
(
"dummy/foo/bar"
);
EXPECT_TRUE
(
result
);
EXPECT_STREQ
(
result
.
archive
.
c_str
(),
"dummy"
);
EXPECT_STREQ
(
result
.
inside
.
c_str
(),
"foo/bar"
);
free
(
path
);
path
=
strdup
(
"config.h/foo/bar"
);
result
=
archive_lookup
(
path
);
result
=
archive_lookup
(
"config.h/foo/bar"
);
EXPECT_TRUE
(
result
);
EXPECT_STREQ
(
result
.
archive
.
c_str
(),
"config.h"
);
EXPECT_STREQ
(
result
.
inside
.
c_str
(),
"foo/bar"
);
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