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
220d9528
Commit
220d9528
authored
Sep 09, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
archive/Plugin: migrate open() from class Error to C++ exceptions
parent
fc7d3f64
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
27 additions
and
49 deletions
+27
-49
ArchiveFile.hxx
src/archive/ArchiveFile.hxx
+0
-1
ArchivePlugin.cxx
src/archive/ArchivePlugin.cxx
+2
-7
ArchivePlugin.hxx
src/archive/ArchivePlugin.hxx
+4
-5
Bzip2ArchivePlugin.cxx
src/archive/plugins/Bzip2ArchivePlugin.cxx
+1
-1
Iso9660ArchivePlugin.cxx
src/archive/plugins/Iso9660ArchivePlugin.cxx
+4
-7
ZzipArchivePlugin.cxx
src/archive/plugins/ZzipArchivePlugin.cxx
+4
-6
Archive.cxx
src/db/update/Archive.cxx
+6
-5
ArchiveInputPlugin.cxx
src/input/plugins/ArchiveInputPlugin.cxx
+1
-5
visit_archive.cxx
test/visit_archive.cxx
+5
-12
No files found.
src/archive/ArchiveFile.hxx
View file @
220d9528
...
...
@@ -22,7 +22,6 @@
class
Mutex
;
class
Cond
;
class
Error
;
struct
ArchivePlugin
;
class
ArchiveVisitor
;
class
InputStream
;
...
...
src/archive/ArchivePlugin.cxx
View file @
220d9528
...
...
@@ -20,20 +20,15 @@
#include "config.h"
#include "ArchivePlugin.hxx"
#include "fs/Path.hxx"
#include "util/Error.hxx"
#include <assert.h>
ArchiveFile
*
archive_file_open
(
const
ArchivePlugin
*
plugin
,
Path
path
,
Error
&
error
)
archive_file_open
(
const
ArchivePlugin
*
plugin
,
Path
path
)
{
assert
(
plugin
!=
nullptr
);
assert
(
plugin
->
open
!=
nullptr
);
assert
(
!
path
.
IsNull
());
ArchiveFile
*
file
=
plugin
->
open
(
path
,
error
);
assert
((
file
==
nullptr
)
==
error
.
IsDefined
());
return
file
;
return
plugin
->
open
(
path
);
}
src/archive/ArchivePlugin.hxx
View file @
220d9528
...
...
@@ -22,7 +22,6 @@
class
ArchiveFile
;
class
Path
;
class
Error
;
struct
ArchivePlugin
{
const
char
*
name
;
...
...
@@ -43,9 +42,10 @@ struct ArchivePlugin {
/**
* tryes to open archive file and associates handle with archive
* returns pointer to handle used is all operations with this archive
* or nullptr when opening fails
*
* Throws std::runtime_error on error.
*/
ArchiveFile
*
(
*
open
)(
Path
path_fs
,
Error
&
error
);
ArchiveFile
*
(
*
open
)(
Path
path_fs
);
/**
* suffixes handled by this plugin.
...
...
@@ -55,7 +55,6 @@ struct ArchivePlugin {
};
ArchiveFile
*
archive_file_open
(
const
ArchivePlugin
*
plugin
,
Path
path
,
Error
&
error
);
archive_file_open
(
const
ArchivePlugin
*
plugin
,
Path
path
);
#endif
src/archive/plugins/Bzip2ArchivePlugin.cxx
View file @
220d9528
...
...
@@ -127,7 +127,7 @@ Bzip2InputStream::Open()
/* archive open && listing routine */
static
ArchiveFile
*
bz2_open
(
Path
pathname
,
gcc_unused
Error
&
error
)
bz2_open
(
Path
pathname
)
{
static
Mutex
mutex
;
static
Cond
cond
;
...
...
src/archive/plugins/Iso9660ArchivePlugin.cxx
View file @
220d9528
...
...
@@ -123,16 +123,13 @@ Iso9660ArchiveFile::Visit(char *path, size_t length, size_t capacity,
}
static
ArchiveFile
*
iso9660_archive_open
(
Path
pathname
,
Error
&
error
)
iso9660_archive_open
(
Path
pathname
)
{
/* open archive */
auto
iso
=
iso9660_open
(
pathname
.
c_str
());
if
(
iso
==
nullptr
)
{
error
.
Format
(
iso9660_domain
,
"Failed to open ISO9660 file %s"
,
pathname
.
c_str
());
return
nullptr
;
}
if
(
iso
==
nullptr
)
throw
FormatRuntimeError
(
"Failed to open ISO9660 file %s"
,
pathname
.
c_str
());
return
new
Iso9660ArchiveFile
(
iso
);
}
...
...
src/archive/plugins/ZzipArchivePlugin.cxx
View file @
220d9528
...
...
@@ -68,14 +68,12 @@ static constexpr Domain zzip_domain("zzip");
/* archive open && listing routine */
static
ArchiveFile
*
zzip_archive_open
(
Path
pathname
,
Error
&
error
)
zzip_archive_open
(
Path
pathname
)
{
ZZIP_DIR
*
dir
=
zzip_dir_open
(
pathname
.
c_str
(),
nullptr
);
if
(
dir
==
nullptr
)
{
error
.
Format
(
zzip_domain
,
"Failed to open ZIP file %s"
,
pathname
.
c_str
());
return
nullptr
;
}
if
(
dir
==
nullptr
)
throw
FormatRuntimeError
(
"Failed to open ZIP file %s"
,
pathname
.
c_str
());
return
new
ZzipArchiveFile
(
dir
);
}
...
...
src/db/update/Archive.cxx
View file @
220d9528
...
...
@@ -30,11 +30,11 @@
#include "archive/ArchivePlugin.hxx"
#include "archive/ArchiveFile.hxx"
#include "archive/ArchiveVisitor.hxx"
#include "util/Error.hxx"
#include "util/StringCompare.hxx"
#include "Log.hxx"
#include <string>
#include <stdexcept>
#include <string.h>
...
...
@@ -150,10 +150,11 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name,
return
;
/* open archive */
Error
error
;
ArchiveFile
*
file
=
archive_file_open
(
&
plugin
,
path_fs
,
error
);
if
(
file
==
nullptr
)
{
LogError
(
error
);
ArchiveFile
*
file
;
try
{
file
=
archive_file_open
(
&
plugin
,
path_fs
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
LogError
(
e
);
if
(
directory
!=
nullptr
)
editor
.
LockDeleteDirectory
(
directory
);
return
;
...
...
src/input/plugins/ArchiveInputPlugin.cxx
View file @
220d9528
...
...
@@ -29,7 +29,6 @@
#include "fs/Path.hxx"
#include "Log.hxx"
#include "util/ScopeExit.hxx"
#include "util/Error.hxx"
#include <stdexcept>
...
...
@@ -61,10 +60,7 @@ OpenArchiveInputStream(Path path, Mutex &mutex, Cond &cond)
return
nullptr
;
}
Error
error
;
auto
file
=
archive_file_open
(
arplug
,
Path
::
FromFS
(
archive
),
error
);
if
(
file
==
nullptr
)
throw
std
::
runtime_error
(
error
.
GetMessage
());
auto
file
=
archive_file_open
(
arplug
,
Path
::
FromFS
(
archive
));
AtScopeExit
(
file
)
{
file
->
Close
();
...
...
test/visit_archive.cxx
View file @
220d9528
...
...
@@ -27,7 +27,6 @@
#include "archive/ArchiveFile.hxx"
#include "archive/ArchiveVisitor.hxx"
#include "fs/Path.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include <stdexcept>
...
...
@@ -46,8 +45,6 @@ class MyArchiveVisitor final : public ArchiveVisitor {
int
main
(
int
argc
,
char
**
argv
)
try
{
Error
error
;
if
(
argc
!=
3
)
{
fprintf
(
stderr
,
"Usage: visit_archive PLUGIN PATH
\n
"
);
return
EXIT_FAILURE
;
...
...
@@ -76,15 +73,11 @@ try {
int
result
=
EXIT_SUCCESS
;
ArchiveFile
*
file
=
archive_file_open
(
plugin
,
path
,
error
);
if
(
file
!=
nullptr
)
{
MyArchiveVisitor
visitor
;
file
->
Visit
(
visitor
);
file
->
Close
();
}
else
{
fprintf
(
stderr
,
"%s"
,
error
.
GetMessage
());
result
=
EXIT_FAILURE
;
}
ArchiveFile
*
file
=
archive_file_open
(
plugin
,
path
);
MyArchiveVisitor
visitor
;
file
->
Visit
(
visitor
);
file
->
Close
();
/* deinitialize everything */
...
...
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