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
3c7cf946
Commit
3c7cf946
authored
Jan 24, 2013
by
Denis Krjuchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Path: convert fs_charset_to_utf8() to static method Path::ToUTF8()
parent
3bd35d18
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
53 deletions
+59
-53
InotifyUpdate.cxx
src/InotifyUpdate.cxx
+6
-6
Mapper.cxx
src/Mapper.cxx
+5
-1
PlaylistFile.cxx
src/PlaylistFile.cxx
+3
-4
PlaylistSong.cxx
src/PlaylistSong.cxx
+6
-9
UpdateWalk.cxx
src/UpdateWalk.cxx
+8
-11
Path.cxx
src/fs/Path.cxx
+21
-14
Path.hxx
src/fs/Path.hxx
+10
-8
No files found.
src/InotifyUpdate.cxx
View file @
3c7cf946
...
@@ -289,14 +289,14 @@ mpd_inotify_callback(int wd, unsigned mask,
...
@@ -289,14 +289,14 @@ mpd_inotify_callback(int wd, unsigned mask,
(
mask
&
(
IN_CREATE
|
IN_ISDIR
))
==
(
IN_CREATE
|
IN_ISDIR
)))
{
(
mask
&
(
IN_CREATE
|
IN_ISDIR
))
==
(
IN_CREATE
|
IN_ISDIR
)))
{
/* a file was changed, or a directory was
/* a file was changed, or a directory was
moved/deleted: queue a database update */
moved/deleted: queue a database update */
char
*
uri_utf8
=
uri_fs
!=
NULL
?
fs_charset_to_utf8
(
uri_fs
)
:
g_strdup
(
""
);
if
(
uri_utf8
!=
NULL
)
{
if
(
uri_fs
!=
nullptr
)
{
inotify_queue
->
Enqueue
(
uri_utf8
);
const
std
::
string
uri_utf8
=
Path
::
ToUTF8
(
uri_fs
);
g_free
(
uri_utf8
);
if
(
!
uri_utf8
.
empty
())
inotify_queue
->
Enqueue
(
uri_utf8
.
c_str
());
}
}
else
inotify_queue
->
Enqueue
(
""
);
}
}
g_free
(
uri_fs
);
g_free
(
uri_fs
);
...
...
src/Mapper.cxx
View file @
3c7cf946
...
@@ -246,7 +246,11 @@ map_fs_to_utf8(const char *path_fs)
...
@@ -246,7 +246,11 @@ map_fs_to_utf8(const char *path_fs)
while
(
path_fs
[
0
]
==
G_DIR_SEPARATOR
)
while
(
path_fs
[
0
]
==
G_DIR_SEPARATOR
)
++
path_fs
;
++
path_fs
;
return
fs_charset_to_utf8
(
path_fs
);
const
std
::
string
path_utf8
=
Path
::
ToUTF8
(
path_fs
);
if
(
path_utf8
.
empty
())
return
nullptr
;
return
g_strdup
(
path_utf8
.
c_str
());
}
}
const
Path
&
const
Path
&
...
...
src/PlaylistFile.cxx
View file @
3c7cf946
...
@@ -163,13 +163,12 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
...
@@ -163,13 +163,12 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
char
*
name
=
g_strndup
(
name_fs
,
char
*
name
=
g_strndup
(
name_fs
,
name_length
+
1
-
sizeof
(
PLAYLIST_FILE_SUFFIX
));
name_length
+
1
-
sizeof
(
PLAYLIST_FILE_SUFFIX
));
char
*
name_utf8
=
fs_charset_to_utf
8
(
name
);
std
::
string
name_utf8
=
Path
::
ToUTF
8
(
name
);
g_free
(
name
);
g_free
(
name
);
if
(
name_utf8
==
NULL
)
if
(
name_utf8
.
empty
()
)
return
false
;
return
false
;
info
.
name
=
name_utf8
;
info
.
name
=
std
::
move
(
name_utf8
);
g_free
(
name_utf8
);
info
.
mtime
=
st
.
st_mtime
;
info
.
mtime
=
st
.
st_mtime
;
return
true
;
return
true
;
}
}
...
...
src/PlaylistSong.cxx
View file @
3c7cf946
...
@@ -65,18 +65,15 @@ apply_song_metadata(struct song *dest, const struct song *src)
...
@@ -65,18 +65,15 @@ apply_song_metadata(struct song *dest, const struct song *src)
return
dest
;
return
dest
;
if
(
song_in_database
(
dest
))
{
if
(
song_in_database
(
dest
))
{
c
har
*
path_fs
=
map_song_fs
(
dest
).
Steal
(
);
c
onst
Path
&
path_fs
=
map_song_fs
(
dest
);
if
(
path_fs
==
nullptr
)
if
(
path_fs
.
IsNull
()
)
return
dest
;
return
dest
;
char
*
path_utf8
=
fs_charset_to_utf8
(
path_fs
);
std
::
string
path_utf8
=
path_fs
.
ToUTF8
();
if
(
path_utf8
!=
NULL
)
if
(
path_utf8
.
empty
())
g_free
(
path_fs
);
path_utf8
=
path_fs
.
c_str
();
else
path_utf8
=
path_fs
;
tmp
=
song_file_new
(
path_utf8
,
NULL
);
tmp
=
song_file_new
(
path_utf8
.
c_str
(),
NULL
);
g_free
(
path_utf8
);
merge_song_metadata
(
tmp
,
dest
,
src
);
merge_song_metadata
(
tmp
,
dest
,
src
);
}
else
{
}
else
{
...
...
src/UpdateWalk.cxx
View file @
3c7cf946
...
@@ -373,28 +373,25 @@ update_directory(Directory *directory, const struct stat *st)
...
@@ -373,28 +373,25 @@ update_directory(Directory *directory, const struct stat *st)
struct
dirent
*
ent
;
struct
dirent
*
ent
;
while
((
ent
=
readdir
(
dir
)))
{
while
((
ent
=
readdir
(
dir
)))
{
char
*
utf8
;
std
::
string
utf8
;
struct
stat
st2
;
struct
stat
st2
;
if
(
skip_path
(
ent
->
d_name
)
||
exclude_list
.
Check
(
ent
->
d_name
))
if
(
skip_path
(
ent
->
d_name
)
||
exclude_list
.
Check
(
ent
->
d_name
))
continue
;
continue
;
utf8
=
fs_charset_to_utf
8
(
ent
->
d_name
);
utf8
=
Path
::
ToUTF
8
(
ent
->
d_name
);
if
(
utf8
==
NULL
)
if
(
utf8
.
empty
()
)
continue
;
continue
;
if
(
skip_symlink
(
directory
,
utf8
))
{
if
(
skip_symlink
(
directory
,
utf8
.
c_str
()))
{
modified
|=
delete_name_in
(
directory
,
utf8
);
modified
|=
delete_name_in
(
directory
,
utf8
.
c_str
());
g_free
(
utf8
);
continue
;
continue
;
}
}
if
(
stat_directory_child
(
directory
,
utf8
,
&
st2
)
==
0
)
if
(
stat_directory_child
(
directory
,
utf8
.
c_str
()
,
&
st2
)
==
0
)
update_directory_child
(
directory
,
utf8
,
&
st2
);
update_directory_child
(
directory
,
utf8
.
c_str
()
,
&
st2
);
else
else
modified
|=
delete_name_in
(
directory
,
utf8
);
modified
|=
delete_name_in
(
directory
,
utf8
.
c_str
());
g_free
(
utf8
);
}
}
closedir
(
dir
);
closedir
(
dir
);
...
...
src/fs/Path.cxx
View file @
3c7cf946
...
@@ -48,24 +48,31 @@
...
@@ -48,24 +48,31 @@
static
char
*
fs_charset
;
static
char
*
fs_charset
;
std
::
string
Path
::
ToUTF8
(
)
const
std
::
string
Path
::
ToUTF8
(
const_pointer
path_fs
)
{
{
if
(
value
==
nullptr
)
if
(
path_fs
==
nullptr
)
return
std
::
string
();
return
std
::
string
();
char
*
path_utf8
=
fs_charset_to_utf8
(
value
);
if
(
path_utf8
==
nullptr
)
GIConv
conv
=
g_iconv_open
(
"utf-8"
,
fs_charset
);
if
(
conv
==
reinterpret_cast
<
GIConv
>
(
-
1
))
return
std
::
string
();
return
std
::
string
();
std
::
string
result
=
value
;
g_free
(
path_utf8
);
return
value
;
}
char
*
// g_iconv() does not need nul-terminator,
fs_charset_to_utf8
(
const
char
*
path_fs
)
// std::string could be created without it too.
{
char
path_utf8
[
MPD_PATH_MAX_UTF8
-
1
];
return
g_convert
(
path_fs
,
-
1
,
char
*
in
=
const_cast
<
char
*>
(
path_fs
);
"utf-8"
,
fs_charset
,
char
*
out
=
path_utf8
;
NULL
,
NULL
,
NULL
);
size_t
in_left
=
strlen
(
path_fs
);
size_t
out_left
=
sizeof
(
path_utf8
);
size_t
ret
=
g_iconv
(
conv
,
&
in
,
&
in_left
,
&
out
,
&
out_left
);
g_iconv_close
(
conv
);
if
(
ret
==
static_cast
<
size_t
>
(
-
1
)
||
in_left
>
0
)
return
std
::
string
();
return
std
::
string
(
path_utf8
,
sizeof
(
path_utf8
)
-
out_left
);
}
}
char
*
char
*
...
...
src/fs/Path.hxx
View file @
3c7cf946
...
@@ -49,13 +49,6 @@ void path_global_init();
...
@@ -49,13 +49,6 @@ void path_global_init();
void
path_global_finish
();
void
path_global_finish
();
/**
/**
* Converts a file name in the filesystem charset to UTF-8. Returns
* NULL on failure.
*/
char
*
fs_charset_to_utf8
(
const
char
*
path_fs
);
/**
* Converts a file name in UTF-8 to the filesystem charset. Returns a
* Converts a file name in UTF-8 to the filesystem charset. Returns a
* duplicate of the UTF-8 string on failure.
* duplicate of the UTF-8 string on failure.
*/
*/
...
@@ -174,6 +167,13 @@ public:
...
@@ -174,6 +167,13 @@ public:
}
}
/**
/**
* Convert the path to UTF-8.
* Returns empty string on error or if #path_fs is null pointer.
*/
gcc_pure
static
std
::
string
ToUTF8
(
const_pointer
path_fs
);
/**
* Copy a #Path object.
* Copy a #Path object.
*/
*/
Path
&
operator
=
(
const
Path
&
other
)
{
Path
&
operator
=
(
const
Path
&
other
)
{
...
@@ -257,7 +257,9 @@ public:
...
@@ -257,7 +257,9 @@ public:
* Returns empty string on error or if this instance is "nulled"
* Returns empty string on error or if this instance is "nulled"
* (#IsNull returns true).
* (#IsNull returns true).
*/
*/
std
::
string
ToUTF8
()
const
;
std
::
string
ToUTF8
()
const
{
return
ToUTF8
(
value
);
}
};
};
#endif
#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