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
fd2c6b8a
Commit
fd2c6b8a
authored
Nov 29, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/Charset: return Error on SetFSCharset() failure
Don't abort the process, let the caller decide instead.
parent
5b1db917
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
17 deletions
+37
-17
Main.cxx
src/Main.cxx
+4
-1
Charset.cxx
src/fs/Charset.cxx
+19
-8
Charset.hxx
src/fs/Charset.hxx
+4
-2
Config.cxx
src/fs/Config.cxx
+6
-4
Config.hxx
src/fs/Config.hxx
+4
-2
No files found.
src/Main.cxx
View file @
fd2c6b8a
...
...
@@ -551,7 +551,10 @@ static int mpd_main_after_fork(struct options options)
GlobalEvents
::
Register
(
GlobalEvents
::
SHUTDOWN
,
shutdown_event_emitted
);
#endif
ConfigureFS
();
if
(
!
ConfigureFS
(
error
))
{
LogError
(
error
);
return
EXIT_FAILURE
;
}
if
(
!
glue_mapper_init
(
error
))
{
LogError
(
error
);
...
...
src/fs/Charset.cxx
View file @
fd2c6b8a
...
...
@@ -21,9 +21,10 @@
#include "Charset.hxx"
#include "Domain.hxx"
#include "Limits.hxx"
#include "system/FatalError.hxx"
#include "Log.hxx"
#include "Traits.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#ifdef HAVE_GLIB
#include <glib.h>
...
...
@@ -36,6 +37,8 @@
#ifdef HAVE_GLIB
static
constexpr
Domain
convert_domain
(
"convert"
);
/**
* Maximal number of bytes required to represent path name in UTF-8
* (including nul-terminator).
...
...
@@ -50,29 +53,37 @@ static std::string fs_charset;
gcc_pure
static
bool
IsSupportedCharset
(
const
char
*
charset
)
CheckCharset
(
const
char
*
charset
,
Error
&
error
)
{
/* convert a space to check if the charset is valid */
char
*
test
=
g_convert
(
" "
,
1
,
charset
,
"UTF-8"
,
nullptr
,
nullptr
,
nullptr
);
if
(
test
==
nullptr
)
GError
*
error2
=
nullptr
;
char
*
test
=
g_convert
(
" "
,
1
,
charset
,
"UTF-8"
,
nullptr
,
nullptr
,
&
error2
);
if
(
test
==
nullptr
)
{
error
.
Set
(
convert_domain
,
error2
->
code
,
error2
->
message
);
g_error_free
(
error2
);
return
false
;
}
g_free
(
test
);
return
true
;
}
void
SetFSCharset
(
const
char
*
charset
)
bool
SetFSCharset
(
const
char
*
charset
,
Error
&
error
)
{
assert
(
charset
!=
nullptr
);
if
(
!
IsSupportedCharset
(
charset
))
FormatFatalError
(
"invalid filesystem charset: %s"
,
charset
);
if
(
!
CheckCharset
(
charset
,
error
))
{
error
.
FormatPrefix
(
"Failed to initialize filesystem charset '%s': "
,
charset
);
return
false
;
}
fs_charset
=
charset
;
FormatDebug
(
path_domain
,
"SetFSCharset: fs charset is: %s"
,
fs_charset
.
c_str
());
return
true
;
}
#endif
...
...
src/fs/Charset.hxx
View file @
fd2c6b8a
...
...
@@ -25,6 +25,8 @@
#include <string>
class
Error
;
/**
* Gets file system character set name.
*/
...
...
@@ -32,8 +34,8 @@ gcc_const
const
char
*
GetFSCharset
();
void
SetFSCharset
(
const
char
*
charset
);
bool
SetFSCharset
(
const
char
*
charset
,
Error
&
error
);
/**
* Convert the path to UTF-8.
...
...
src/fs/Config.cxx
View file @
fd2c6b8a
...
...
@@ -29,8 +29,8 @@
#include <glib.h>
#endif
void
ConfigureFS
()
bool
ConfigureFS
(
Error
&
error
)
{
#ifdef HAVE_GLIB
const
char
*
charset
=
nullptr
;
...
...
@@ -55,7 +55,9 @@ ConfigureFS()
#endif
}
if
(
charset
!=
nullptr
)
SetFSCharset
(
charset
);
return
charset
==
nullptr
||
SetFSCharset
(
charset
,
error
);
#else
(
void
)
error
;
return
true
;
#endif
}
src/fs/Config.hxx
View file @
fd2c6b8a
...
...
@@ -22,10 +22,12 @@
#include "check.h"
class
Error
;
/**
* Performs global one-time initialization of this class.
*/
void
ConfigureFS
();
bool
ConfigureFS
(
Error
&
error
);
#endif
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