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
4aab97cc
Commit
4aab97cc
authored
Nov 07, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config/Path: throw std::runtime_error on error
parent
4cd21f1e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
42 additions
and
68 deletions
+42
-68
Block.cxx
src/config/Block.cxx
+1
-10
Block.hxx
src/config/Block.hxx
+0
-1
ConfigPath.cxx
src/config/ConfigPath.cxx
+19
-25
ConfigPath.hxx
src/config/ConfigPath.hxx
+4
-2
Param.cxx
src/config/Param.cxx
+6
-18
Param.hxx
src/config/Param.hxx
+0
-7
RecorderOutputPlugin.cxx
src/output/plugins/RecorderOutputPlugin.cxx
+12
-5
No files found.
src/config/Block.cxx
View file @
4aab97cc
...
...
@@ -24,7 +24,6 @@
#include "system/FatalError.hxx"
#include "fs/AllocatedPath.hxx"
#include "util/RuntimeError.hxx"
#include "util/Error.hxx"
#include <assert.h>
#include <stdlib.h>
...
...
@@ -94,12 +93,10 @@ ConfigBlock::GetBlockValue(const char *name, const char *default_value) const
AllocatedPath
ConfigBlock
::
GetPath
(
const
char
*
name
,
const
char
*
default_value
)
const
{
int
line2
=
line
;
const
char
*
s
;
const
BlockParam
*
bp
=
GetBlockParam
(
name
);
if
(
bp
!=
nullptr
)
{
line2
=
bp
->
line
;
s
=
bp
->
value
.
c_str
();
}
else
{
if
(
default_value
==
nullptr
)
...
...
@@ -108,13 +105,7 @@ ConfigBlock::GetPath(const char *name, const char *default_value) const
s
=
default_value
;
}
Error
error
;
AllocatedPath
path
=
ParsePath
(
s
,
error
);
if
(
gcc_unlikely
(
path
.
IsNull
()))
throw
FormatRuntimeError
(
"Invalid path in
\"
%s
\"
at line %i: %s"
,
name
,
line2
,
error
.
GetMessage
());
return
path
;
return
ParsePath
(
s
);
}
int
...
...
src/config/Block.hxx
View file @
4aab97cc
...
...
@@ -27,7 +27,6 @@
#include <string>
#include <vector>
class
Error
;
class
AllocatedPath
;
struct
BlockParam
{
...
...
src/config/ConfigPath.cxx
View file @
4aab97cc
...
...
@@ -23,7 +23,7 @@
#include "fs/Traits.hxx"
#include "fs/Domain.hxx"
#include "fs/StandardDirectory.hxx"
#include "util/Error.hxx"
#include "util/
Runtime
Error.hxx"
#include "ConfigGlobal.hxx"
#include <assert.h>
...
...
@@ -36,14 +36,11 @@
* Determine a given user's home directory.
*/
static
AllocatedPath
GetHome
(
const
char
*
user
,
Error
&
error
)
GetHome
(
const
char
*
user
)
{
AllocatedPath
result
=
GetHomeDir
(
user
);
if
(
result
.
IsNull
())
{
error
.
Format
(
path_domain
,
"no such user: %s"
,
user
);
return
AllocatedPath
::
Null
();
}
if
(
result
.
IsNull
())
throw
FormatRuntimeError
(
"no such user: %s"
,
user
);
return
result
;
}
...
...
@@ -52,34 +49,33 @@ GetHome(const char *user, Error &error)
* Determine the current user's home directory.
*/
static
AllocatedPath
GetHome
(
Error
&
error
)
GetHome
()
{
AllocatedPath
result
=
GetHomeDir
();
if
(
result
.
IsNull
())
{
error
.
Set
(
path_domain
,
"problems getting home for current user"
);
return
AllocatedPath
::
Null
();
}
if
(
result
.
IsNull
())
throw
std
::
runtime_error
(
"problems getting home for current user"
);
return
result
;
}
/**
* Determine the configured user's home directory.
*
* Throws #std::runtime_error on error.
*/
static
AllocatedPath
GetConfiguredHome
(
Error
&
error
)
GetConfiguredHome
()
{
const
char
*
user
=
config_get_string
(
ConfigOption
::
USER
);
return
user
!=
nullptr
?
GetHome
(
user
,
error
)
:
GetHome
(
error
);
?
GetHome
(
user
)
:
GetHome
();
}
#endif
AllocatedPath
ParsePath
(
const
char
*
path
,
Error
&
error
)
ParsePath
(
const
char
*
path
)
{
assert
(
path
!=
nullptr
);
...
...
@@ -88,12 +84,12 @@ ParsePath(const char *path, Error &error)
++
path
;
if
(
*
path
==
'\0'
)
return
GetConfiguredHome
(
error
);
return
GetConfiguredHome
();
AllocatedPath
home
=
AllocatedPath
::
Null
();
if
(
*
path
==
'/'
)
{
home
=
GetConfiguredHome
(
error
);
home
=
GetConfiguredHome
();
++
path
;
}
else
{
...
...
@@ -102,7 +98,7 @@ ParsePath(const char *path, Error &error)
?
path
+
strlen
(
path
)
:
slash
;
const
std
::
string
user
(
path
,
end
);
home
=
GetHome
(
user
.
c_str
()
,
error
);
home
=
GetHome
(
user
.
c_str
());
if
(
slash
==
nullptr
)
return
home
;
...
...
@@ -113,18 +109,16 @@ ParsePath(const char *path, Error &error)
if
(
home
.
IsNull
())
return
AllocatedPath
::
Null
();
AllocatedPath
path2
=
AllocatedPath
::
FromUTF8
(
path
,
error
);
AllocatedPath
path2
=
AllocatedPath
::
FromUTF8
Throw
(
path
);
if
(
path2
.
IsNull
())
return
AllocatedPath
::
Null
();
return
AllocatedPath
::
Build
(
home
,
path2
);
}
else
if
(
!
PathTraitsUTF8
::
IsAbsolute
(
path
))
{
error
.
Format
(
path_domain
,
"not an absolute path: %s"
,
path
);
return
AllocatedPath
::
Null
();
throw
FormatRuntimeError
(
"not an absolute path: %s"
,
path
);
}
else
{
#endif
return
AllocatedPath
::
FromUTF8
(
path
,
error
);
return
AllocatedPath
::
FromUTF8
Throw
(
path
);
#ifndef WIN32
}
#endif
...
...
src/config/ConfigPath.hxx
View file @
4aab97cc
...
...
@@ -21,9 +21,11 @@
#define MPD_CONFIG_PATH_HXX
class
AllocatedPath
;
class
Error
;
/**
* Throws #std::runtime_error on error.
*/
AllocatedPath
ParsePath
(
const
char
*
path
,
Error
&
error
);
ParsePath
(
const
char
*
path
);
#endif
src/config/Param.cxx
View file @
4aab97cc
...
...
@@ -21,7 +21,7 @@
#include "Param.hxx"
#include "ConfigPath.hxx"
#include "fs/AllocatedPath.hxx"
#include "util/Error.hxx"
#include "util/
Runtime
Error.hxx"
#include <stdexcept>
...
...
@@ -34,24 +34,12 @@ ConfigParam::~ConfigParam()
}
AllocatedPath
ConfigParam
::
GetPath
(
Error
&
error
)
const
{
auto
path
=
ParsePath
(
value
.
c_str
(),
error
);
if
(
gcc_unlikely
(
path
.
IsNull
()))
error
.
FormatPrefix
(
"Invalid path at line %i: "
,
line
);
return
path
;
}
AllocatedPath
ConfigParam
::
GetPath
()
const
{
Error
error
;
auto
path
=
ParsePath
(
value
.
c_str
(),
error
);
if
(
gcc_unlikely
(
path
.
IsNull
()))
throw
std
::
runtime_error
(
error
.
GetMessage
());
return
path
;
try
{
return
ParsePath
(
value
.
c_str
());
}
catch
(...)
{
std
::
throw_with_nested
(
FormatRuntimeError
(
"Invalid path at line %i: "
,
line
));
}
}
src/config/Param.hxx
View file @
4aab97cc
...
...
@@ -68,13 +68,6 @@ struct ConfigParam {
/**
* Parse the value as a path. If there is a tilde prefix, it
* is expanded. If the path could not be parsed, returns
* AllocatedPath::Null() and sets the error.
*/
AllocatedPath
GetPath
(
Error
&
error
)
const
;
/**
* Parse the value as a path. If there is a tilde prefix, it
* is expanded.
*
* Throws #std::runtime_error on error.
...
...
src/output/plugins/RecorderOutputPlugin.cxx
View file @
4aab97cc
...
...
@@ -33,6 +33,9 @@
#include "fs/io/FileOutputStream.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "util/ScopeExit.hxx"
#include <stdexcept>
#include <assert.h>
#include <stdlib.h>
...
...
@@ -369,11 +372,14 @@ RecorderOutput::SendTag(const Tag &tag)
return
;
}
Error
error
;
AllocatedPath
new_path
=
ParsePath
(
p
,
error
);
free
(
p
);
if
(
new_path
.
IsNull
())
{
LogError
(
error
);
AtScopeExit
(
p
)
{
free
(
p
);
};
AllocatedPath
new_path
=
AllocatedPath
::
Null
();
try
{
new_path
=
ParsePath
(
p
);
}
catch
(
const
std
::
runtime_error
&
e
)
{
LogError
(
e
);
FinishFormat
();
return
;
}
...
...
@@ -381,6 +387,7 @@ RecorderOutput::SendTag(const Tag &tag)
if
(
new_path
!=
path
)
{
FinishFormat
();
Error
error
;
if
(
!
ReopenFormat
(
std
::
move
(
new_path
),
error
))
{
LogError
(
error
);
return
;
...
...
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