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
d765182b
Commit
d765182b
authored
Nov 02, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config/Global: _get_path() throws exception on error
parent
5a63d1d5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
60 deletions
+25
-60
Main.cxx
src/Main.cxx
+17
-45
ConfigGlobal.cxx
src/config/ConfigGlobal.cxx
+2
-3
ConfigGlobal.hxx
src/config/ConfigGlobal.hxx
+4
-4
Configured.cxx
src/storage/Configured.cxx
+2
-8
No files found.
src/Main.cxx
View file @
d765182b
...
@@ -129,34 +129,23 @@ Instance *instance;
...
@@ -129,34 +129,23 @@ Instance *instance;
#ifdef ENABLE_DAEMON
#ifdef ENABLE_DAEMON
static
bool
static
void
glue_daemonize_init
(
const
struct
options
*
options
,
Error
&
error
)
glue_daemonize_init
(
const
struct
options
*
options
)
{
{
auto
pid_file
=
config_get_path
(
ConfigOption
::
PID_FILE
,
error
);
if
(
pid_file
.
IsNull
()
&&
error
.
IsDefined
())
return
false
;
daemonize_init
(
config_get_string
(
ConfigOption
::
USER
,
nullptr
),
daemonize_init
(
config_get_string
(
ConfigOption
::
USER
,
nullptr
),
config_get_string
(
ConfigOption
::
GROUP
,
nullptr
),
config_get_string
(
ConfigOption
::
GROUP
,
nullptr
),
std
::
move
(
pid_file
));
config_get_path
(
ConfigOption
::
PID_FILE
));
if
(
options
->
kill
)
if
(
options
->
kill
)
daemonize_kill
();
daemonize_kill
();
return
true
;
}
}
#endif
#endif
static
bool
static
void
glue_mapper_init
(
Error
&
error
)
glue_mapper_init
()
{
{
auto
playlist_dir
=
config_get_path
(
ConfigOption
::
PLAYLIST_DIR
,
error
);
mapper_init
(
config_get_path
(
ConfigOption
::
PLAYLIST_DIR
));
if
(
playlist_dir
.
IsNull
()
&&
error
.
IsDefined
())
return
false
;
mapper_init
(
std
::
move
(
playlist_dir
));
return
true
;
}
}
#ifdef ENABLE_DATABASE
#ifdef ENABLE_DATABASE
...
@@ -232,37 +221,30 @@ InitDatabaseAndStorage()
...
@@ -232,37 +221,30 @@ InitDatabaseAndStorage()
* Configure and initialize the sticker subsystem.
* Configure and initialize the sticker subsystem.
*/
*/
static
void
static
void
glue_sticker_init
(
void
)
glue_sticker_init
()
{
{
#ifdef ENABLE_SQLITE
#ifdef ENABLE_SQLITE
Error
error
;
auto
sticker_file
=
config_get_path
(
ConfigOption
::
STICKER_FILE
);
auto
sticker_file
=
config_get_path
(
ConfigOption
::
STICKER_FILE
,
error
);
if
(
sticker_file
.
IsNull
())
if
(
sticker_file
.
IsNull
())
{
if
(
error
.
IsDefined
())
FatalError
(
error
);
return
;
return
;
}
sticker_global_init
(
std
::
move
(
sticker_file
));
sticker_global_init
(
std
::
move
(
sticker_file
));
#endif
#endif
}
}
static
bool
static
void
glue_state_file_init
(
Error
&
error
)
glue_state_file_init
()
{
{
auto
path_fs
=
config_get_path
(
ConfigOption
::
STATE_FILE
,
error
);
auto
path_fs
=
config_get_path
(
ConfigOption
::
STATE_FILE
);
if
(
path_fs
.
IsNull
())
{
if
(
path_fs
.
IsNull
())
{
if
(
error
.
IsDefined
())
return
false
;
#ifdef ANDROID
#ifdef ANDROID
const
auto
cache_dir
=
GetUserCacheDir
();
const
auto
cache_dir
=
GetUserCacheDir
();
if
(
cache_dir
.
IsNull
())
if
(
cache_dir
.
IsNull
())
return
true
;
return
;
path_fs
=
AllocatedPath
::
Build
(
cache_dir
,
"state"
);
path_fs
=
AllocatedPath
::
Build
(
cache_dir
,
"state"
);
#else
#else
return
true
;
return
;
#endif
#endif
}
}
...
@@ -274,7 +256,6 @@ glue_state_file_init(Error &error)
...
@@ -274,7 +256,6 @@ glue_state_file_init(Error &error)
*
instance
->
partition
,
*
instance
->
partition
,
instance
->
event_loop
);
instance
->
event_loop
);
instance
->
state_file
->
Read
();
instance
->
state_file
->
Read
();
return
true
;
}
}
/**
/**
...
@@ -425,10 +406,7 @@ try {
...
@@ -425,10 +406,7 @@ try {
#endif
#endif
#ifdef ENABLE_DAEMON
#ifdef ENABLE_DAEMON
if
(
!
glue_daemonize_init
(
&
options
,
error
))
{
glue_daemonize_init
(
&
options
);
LogError
(
error
);
return
EXIT_FAILURE
;
}
#endif
#endif
stats_global_init
();
stats_global_init
();
...
@@ -490,10 +468,7 @@ try {
...
@@ -490,10 +468,7 @@ try {
ConfigureFS
();
ConfigureFS
();
if
(
!
glue_mapper_init
(
error
))
{
glue_mapper_init
();
LogError
(
error
);
return
EXIT_FAILURE
;
}
initPermissions
();
initPermissions
();
spl_global_init
();
spl_global_init
();
...
@@ -551,10 +526,7 @@ try {
...
@@ -551,10 +526,7 @@ try {
}
}
#endif
#endif
if
(
!
glue_state_file_init
(
error
))
{
glue_state_file_init
();
LogError
(
error
);
return
EXIT_FAILURE
;
}
instance
->
partition
->
outputs
.
SetReplayGainMode
(
replay_gain_get_real_mode
(
instance
->
partition
->
playlist
.
queue
.
random
));
instance
->
partition
->
outputs
.
SetReplayGainMode
(
replay_gain_get_real_mode
(
instance
->
partition
->
playlist
.
queue
.
random
));
...
...
src/config/ConfigGlobal.cxx
View file @
d765182b
...
@@ -28,7 +28,6 @@
...
@@ -28,7 +28,6 @@
#include "ConfigError.hxx"
#include "ConfigError.hxx"
#include "fs/Path.hxx"
#include "fs/Path.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/AllocatedPath.hxx"
#include "util/Error.hxx"
#include "system/FatalError.hxx"
#include "system/FatalError.hxx"
#include "Log.hxx"
#include "Log.hxx"
...
@@ -122,13 +121,13 @@ config_get_string(ConfigOption option, const char *default_value)
...
@@ -122,13 +121,13 @@ config_get_string(ConfigOption option, const char *default_value)
}
}
AllocatedPath
AllocatedPath
config_get_path
(
ConfigOption
option
,
Error
&
error
)
config_get_path
(
ConfigOption
option
)
{
{
const
auto
*
param
=
config_get_param
(
option
);
const
auto
*
param
=
config_get_param
(
option
);
if
(
param
==
nullptr
)
if
(
param
==
nullptr
)
return
AllocatedPath
::
Null
();
return
AllocatedPath
::
Null
();
return
param
->
GetPath
(
error
);
return
param
->
GetPath
();
}
}
unsigned
unsigned
...
...
src/config/ConfigGlobal.hxx
View file @
d765182b
...
@@ -23,7 +23,6 @@
...
@@ -23,7 +23,6 @@
#include "ConfigOption.hxx"
#include "ConfigOption.hxx"
#include "Compiler.h"
#include "Compiler.h"
class
Error
;
class
Path
;
class
Path
;
class
AllocatedPath
;
class
AllocatedPath
;
struct
ConfigParam
;
struct
ConfigParam
;
...
@@ -78,11 +77,12 @@ config_get_string(enum ConfigOption option, const char *default_value=nullptr);
...
@@ -78,11 +77,12 @@ config_get_string(enum ConfigOption option, const char *default_value=nullptr);
/**
/**
* Returns an optional configuration variable which contains an
* Returns an optional configuration variable which contains an
* absolute path. If there is a tilde prefix, it is expanded.
* absolute path. If there is a tilde prefix, it is expanded.
* Returns AllocatedPath::Null() if the value is not present. If the path
* Returns AllocatedPath::Null() if the value is not present.
* could not be parsed, returns AllocatedPath::Null() and sets the error.
*
* Throws #std::runtime_error on error.
*/
*/
AllocatedPath
AllocatedPath
config_get_path
(
enum
ConfigOption
option
,
Error
&
error
);
config_get_path
(
enum
ConfigOption
option
);
gcc_pure
gcc_pure
unsigned
unsigned
...
...
src/storage/Configured.cxx
View file @
d765182b
...
@@ -26,7 +26,6 @@
...
@@ -26,7 +26,6 @@
#include "fs/StandardDirectory.hxx"
#include "fs/StandardDirectory.hxx"
#include "fs/CheckFile.hxx"
#include "fs/CheckFile.hxx"
#include "util/UriUtil.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include "util/RuntimeError.hxx"
#include "util/RuntimeError.hxx"
#include <assert.h>
#include <assert.h>
...
@@ -44,14 +43,9 @@ CreateConfiguredStorageUri(EventLoop &event_loop, const char *uri)
...
@@ -44,14 +43,9 @@ CreateConfiguredStorageUri(EventLoop &event_loop, const char *uri)
static
AllocatedPath
static
AllocatedPath
GetConfiguredMusicDirectory
()
GetConfiguredMusicDirectory
()
{
{
Error
error
;
AllocatedPath
path
=
config_get_path
(
ConfigOption
::
MUSIC_DIR
);
AllocatedPath
path
=
config_get_path
(
ConfigOption
::
MUSIC_DIR
,
error
);
if
(
path
.
IsNull
())
if
(
path
.
IsNull
())
{
if
(
error
.
IsDefined
())
throw
std
::
runtime_error
(
error
.
GetMessage
());
path
=
GetUserMusicDir
();
path
=
GetUserMusicDir
();
}
return
path
;
return
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