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
37862f0f
Commit
37862f0f
authored
Dec 28, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PlaylistFile: convert more APIs from Error to std::exception
parent
1f184f4a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
63 deletions
+44
-63
PlaylistFile.cxx
src/PlaylistFile.cxx
+28
-42
PlaylistFile.hxx
src/PlaylistFile.hxx
+6
-6
PlaylistCommands.cxx
src/command/PlaylistCommands.cxx
+10
-15
No files found.
src/PlaylistFile.cxx
View file @
37862f0f
...
...
@@ -126,20 +126,20 @@ spl_map_to_fs(const char *name_utf8)
}
/**
*
Create an #Error
for the current errno.
*
Throw an exception
for the current errno.
*/
static
void
playlist_errno
(
Error
&
error
)
ThrowPlaylistErrno
(
)
{
switch
(
errno
)
{
case
ENOENT
:
error
.
Set
(
playlist_domain
,
int
(
PlaylistResult
::
NO_SUCH_LIST
),
"No such playlist"
);
break
;
throw
PlaylistError
(
PlaylistResult
::
NO_SUCH_LIST
,
"No such playlist"
);
default
:
error
.
SetErrno
();
break
;
throw
std
::
system_error
(
std
::
error_code
(
errno
,
std
::
system_category
()),
"Error"
);
}
}
...
...
@@ -303,37 +303,31 @@ spl_move_index(const char *utf8path, unsigned src, unsigned dest)
idle_add
(
IDLE_STORED_PLAYLIST
);
}
bool
spl_clear
(
const
char
*
utf8path
,
Error
&
error
)
void
spl_clear
(
const
char
*
utf8path
)
{
const
auto
path_fs
=
spl_map_to_fs
(
utf8path
);
assert
(
!
path_fs
.
IsNull
());
FILE
*
file
=
FOpen
(
path_fs
,
FOpenMode
::
WriteText
);
if
(
file
==
nullptr
)
{
playlist_errno
(
error
);
return
false
;
}
if
(
file
==
nullptr
)
ThrowPlaylistErrno
();
fclose
(
file
);
idle_add
(
IDLE_STORED_PLAYLIST
);
return
true
;
}
bool
spl_delete
(
const
char
*
name_utf8
,
Error
&
error
)
void
spl_delete
(
const
char
*
name_utf8
)
{
const
auto
path_fs
=
spl_map_to_fs
(
name_utf8
);
assert
(
!
path_fs
.
IsNull
());
if
(
!
RemoveFile
(
path_fs
))
{
playlist_errno
(
error
);
return
false
;
}
if
(
!
RemoveFile
(
path_fs
))
ThrowPlaylistErrno
();
idle_add
(
IDLE_STORED_PLAYLIST
);
return
true
;
}
void
...
...
@@ -389,33 +383,25 @@ spl_append_uri(const char *utf8file,
return
true
;
}
static
bool
spl_rename_internal
(
Path
from_path_fs
,
Path
to_path_fs
,
Error
&
error
)
static
void
spl_rename_internal
(
Path
from_path_fs
,
Path
to_path_fs
)
{
if
(
!
FileExists
(
from_path_fs
))
{
error
.
Set
(
playlist_domain
,
int
(
PlaylistResult
::
NO_SUCH_LIST
),
"No such playlist"
);
return
false
;
}
if
(
!
FileExists
(
from_path_fs
))
throw
PlaylistError
(
PlaylistResult
::
NO_SUCH_LIST
,
"No such playlist"
);
if
(
FileExists
(
to_path_fs
))
{
error
.
Set
(
playlist_domain
,
int
(
PlaylistResult
::
LIST_EXISTS
),
"Playlist exists already"
);
return
false
;
}
if
(
FileExists
(
to_path_fs
))
throw
PlaylistError
(
PlaylistResult
::
LIST_EXISTS
,
"Playlist exists already"
);
if
(
!
RenameFile
(
from_path_fs
,
to_path_fs
))
{
playlist_errno
(
error
);
return
false
;
}
if
(
!
RenameFile
(
from_path_fs
,
to_path_fs
))
ThrowPlaylistErrno
();
idle_add
(
IDLE_STORED_PLAYLIST
);
return
true
;
}
bool
spl_rename
(
const
char
*
utf8from
,
const
char
*
utf8to
,
Error
&
error
)
void
spl_rename
(
const
char
*
utf8from
,
const
char
*
utf8to
)
{
const
auto
from_path_fs
=
spl_map_to_fs
(
utf8from
);
assert
(
!
from_path_fs
.
IsNull
());
...
...
@@ -423,5 +409,5 @@ spl_rename(const char *utf8from, const char *utf8to, Error &error)
const
auto
to_path_fs
=
spl_map_to_fs
(
utf8to
);
assert
(
!
to_path_fs
.
IsNull
());
return
spl_rename_internal
(
from_path_fs
,
to_path_fs
,
error
);
spl_rename_internal
(
from_path_fs
,
to_path_fs
);
}
src/PlaylistFile.hxx
View file @
37862f0f
...
...
@@ -62,11 +62,11 @@ LoadPlaylistFile(const char *utf8path);
void
spl_move_index
(
const
char
*
utf8path
,
unsigned
src
,
unsigned
dest
);
bool
spl_clear
(
const
char
*
utf8path
,
Error
&
error
);
void
spl_clear
(
const
char
*
utf8path
);
bool
spl_delete
(
const
char
*
name_utf8
,
Error
&
error
);
void
spl_delete
(
const
char
*
name_utf8
);
void
spl_remove_index
(
const
char
*
utf8path
,
unsigned
pos
);
...
...
@@ -79,7 +79,7 @@ spl_append_uri(const char *path_utf8,
const
SongLoader
&
loader
,
const
char
*
uri_utf8
,
Error
&
error
);
bool
spl_rename
(
const
char
*
utf8from
,
const
char
*
utf8to
,
Error
&
error
);
void
spl_rename
(
const
char
*
utf8from
,
const
char
*
utf8to
);
#endif
src/command/PlaylistCommands.cxx
View file @
37862f0f
...
...
@@ -110,26 +110,22 @@ handle_listplaylistinfo(Client &client, Request args, Response &r)
}
CommandResult
handle_rm
(
gcc_unused
Client
&
client
,
Request
args
,
Response
&
r
)
handle_rm
(
gcc_unused
Client
&
client
,
Request
args
,
gcc_unused
Response
&
r
)
{
const
char
*
const
name
=
args
.
front
();
Error
error
;
return
spl_delete
(
name
,
error
)
?
CommandResult
::
OK
:
print_error
(
r
,
error
);
spl_delete
(
name
);
return
CommandResult
::
OK
;
}
CommandResult
handle_rename
(
gcc_unused
Client
&
client
,
Request
args
,
Response
&
r
)
handle_rename
(
gcc_unused
Client
&
client
,
Request
args
,
gcc_unused
Response
&
r
)
{
const
char
*
const
old_name
=
args
[
0
];
const
char
*
const
new_name
=
args
[
1
];
Error
error
;
return
spl_rename
(
old_name
,
new_name
,
error
)
?
CommandResult
::
OK
:
print_error
(
r
,
error
);
spl_rename
(
old_name
,
new_name
);
return
CommandResult
::
OK
;
}
CommandResult
...
...
@@ -156,14 +152,13 @@ handle_playlistmove(gcc_unused Client &client,
}
CommandResult
handle_playlistclear
(
gcc_unused
Client
&
client
,
Request
args
,
Response
&
r
)
handle_playlistclear
(
gcc_unused
Client
&
client
,
Request
args
,
gcc_unused
Response
&
r
)
{
const
char
*
const
name
=
args
.
front
();
Error
error
;
return
spl_clear
(
name
,
error
)
?
CommandResult
::
OK
:
print_error
(
r
,
error
);
spl_clear
(
name
);
return
CommandResult
::
OK
;
}
CommandResult
...
...
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