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
36d6ead6
Commit
36d6ead6
authored
Dec 16, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/io/GzipOutputStream: use C++ exceptions in constructor
parent
7eae3bc8
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
92 additions
and
33 deletions
+92
-33
Makefile.am
Makefile.am
+3
-1
SimpleDatabasePlugin.cxx
src/db/plugins/simple/SimpleDatabasePlugin.cxx
+1
-4
GzipOutputStream.cxx
src/fs/io/GzipOutputStream.cxx
+5
-8
GzipOutputStream.hxx
src/fs/io/GzipOutputStream.hxx
+3
-12
Error.cxx
src/lib/zlib/Error.cxx
+29
-0
Error.hxx
src/lib/zlib/Error.hxx
+38
-0
run_gzip.cxx
test/run_gzip.cxx
+13
-8
No files found.
Makefile.am
View file @
36d6ead6
...
...
@@ -605,6 +605,7 @@ libfs_a_CPPFLAGS = $(AM_CPPFLAGS) $(ZLIB_CFLAGS)
if
ENABLE_ZLIB
libfs_a_SOURCES
+=
\
src/lib/zlib/Domain.cxx src/lib/zlib/Domain.hxx
\
src/lib/zlib/Error.cxx src/lib/zlib/Error.hxx
\
src/fs/io/GunzipReader.cxx src/fs/io/GunzipReader.hxx
\
src/fs/io/AutoGunzipReader.cxx src/fs/io/AutoGunzipReader.hxx
\
src/fs/io/GzipOutputStream.cxx src/fs/io/GzipOutputStream.hxx
...
...
@@ -1759,7 +1760,8 @@ noinst_PROGRAMS += test/run_gzip test/run_gunzip
test_run_gzip_LDADD
=
\
libutil.a
\
$(FS_LIBS)
test_run_gzip_SOURCES
=
test
/run_gzip.cxx
test_run_gzip_SOURCES
=
test
/run_gzip.cxx
\
src/Log.cxx src/LogBackend.cxx
test_run_gunzip_SOURCES
=
test
/run_gunzip.cxx
\
src/Log.cxx src/LogBackend.cxx
...
...
src/db/plugins/simple/SimpleDatabasePlugin.cxx
View file @
36d6ead6
...
...
@@ -386,10 +386,7 @@ SimpleDatabase::Save(Error &error)
#ifdef ENABLE_ZLIB
std
::
unique_ptr
<
GzipOutputStream
>
gzip
;
if
(
compress
)
{
gzip
.
reset
(
new
GzipOutputStream
(
*
os
,
error
));
if
(
!
gzip
->
IsDefined
())
return
false
;
gzip
.
reset
(
new
GzipOutputStream
(
*
os
));
os
=
gzip
.
get
();
}
#endif
...
...
src/fs/io/GzipOutputStream.cxx
View file @
36d6ead6
...
...
@@ -20,10 +20,10 @@
#include "config.h"
#include "GzipOutputStream.hxx"
#include "lib/zlib/Domain.hxx"
#include "lib/zlib/Error.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
GzipOutputStream
::
GzipOutputStream
(
OutputStream
&
_next
,
Error
&
e
rror
)
GzipOutputStream
::
GzipOutputStream
(
OutputStream
&
_next
)
throw
(
ZlibE
rror
)
:
next
(
_next
)
{
z
.
next_in
=
nullptr
;
...
...
@@ -38,16 +38,13 @@ GzipOutputStream::GzipOutputStream(OutputStream &_next, Error &error)
int
result
=
deflateInit2
(
&
z
,
Z_DEFAULT_COMPRESSION
,
Z_DEFLATED
,
windowBits
|
gzip_encoding
,
8
,
Z_DEFAULT_STRATEGY
);
if
(
result
!=
Z_OK
)
{
z
.
opaque
=
this
;
error
.
Set
(
zlib_domain
,
result
,
zError
(
result
));
}
if
(
result
!=
Z_OK
)
throw
ZlibError
(
result
);
}
GzipOutputStream
::~
GzipOutputStream
()
{
if
(
IsDefined
())
deflateEnd
(
&
z
);
deflateEnd
(
&
z
);
}
bool
...
...
src/fs/io/GzipOutputStream.hxx
View file @
36d6ead6
...
...
@@ -22,13 +22,13 @@
#include "check.h"
#include "OutputStream.hxx"
#include "lib/zlib/Error.hxx"
#include "Compiler.h"
#include <assert.h>
#include <zlib.h>
class
Error
;
class
Domain
;
/**
* A filter that compresses data written to it using zlib, forwarding
...
...
@@ -43,21 +43,12 @@ class GzipOutputStream final : public OutputStream {
public
:
/**
* Construct the filter. Call IsDefined() to check whether
* the constructor has succeeded. If not, #error will hold
* information about the failure.
* Construct the filter.
*/
GzipOutputStream
(
OutputStream
&
_next
,
Error
&
e
rror
);
GzipOutputStream
(
OutputStream
&
_next
)
throw
(
ZlibE
rror
);
~
GzipOutputStream
();
/**
* Check whether the constructor has succeeded.
*/
bool
IsDefined
()
const
{
return
z
.
opaque
==
nullptr
;
}
/**
* Finish the file and write all data remaining in zlib's
* output buffer.
*/
...
...
src/lib/zlib/Error.cxx
0 → 100644
View file @
36d6ead6
/*
* Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "Error.hxx"
#include <zlib.h>
const
char
*
ZlibError
::
what
()
const
noexcept
{
return
zError
(
code
);
}
src/lib/zlib/Error.hxx
0 → 100644
View file @
36d6ead6
/*
* Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_ZLIB_ERROR_HXX
#define MPD_ZLIB_ERROR_HXX
#include <stdexcept>
class
ZlibError
final
:
public
std
::
exception
{
int
code
;
public
:
explicit
ZlibError
(
int
_code
)
:
code
(
_code
)
{}
int
GetCode
()
const
{
return
code
;
}
const
char
*
what
()
const
noexcept
override
;
};
#endif
test/run_gzip.cxx
View file @
36d6ead6
...
...
@@ -20,6 +20,7 @@
#include "config.h"
#include "fs/io/GzipOutputStream.hxx"
#include "fs/io/StdioOutputStream.hxx"
#include "Log.hxx"
#include "util/Error.hxx"
#include <stdio.h>
...
...
@@ -48,9 +49,8 @@ Copy(OutputStream &dest, int src, Error &error)
static
bool
CopyGzip
(
OutputStream
&
_dest
,
int
src
,
Error
&
error
)
{
GzipOutputStream
dest
(
_dest
,
error
);
return
dest
.
IsDefined
()
&&
Copy
(
dest
,
src
,
error
)
&&
GzipOutputStream
dest
(
_dest
);
return
Copy
(
dest
,
src
,
error
)
&&
dest
.
Flush
(
error
);
}
...
...
@@ -69,11 +69,16 @@ main(int argc, gcc_unused char **argv)
return
EXIT_FAILURE
;
}
Error
error
;
if
(
!
CopyGzip
(
stdout
,
STDIN_FILENO
,
error
))
{
fprintf
(
stderr
,
"%s
\n
"
,
error
.
GetMessage
());
try
{
Error
error
;
if
(
!
CopyGzip
(
stdout
,
STDIN_FILENO
,
error
))
{
fprintf
(
stderr
,
"%s
\n
"
,
error
.
GetMessage
());
return
EXIT_FAILURE
;
}
return
EXIT_SUCCESS
;
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
return
EXIT_FAILURE
;
}
return
EXIT_SUCCESS
;
}
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