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
6caf53d1
Commit
6caf53d1
authored
Dec 04, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/FileSystem: RenameFile() throws exception on error
parent
dee6e498
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
30 deletions
+27
-30
PlaylistFile.cxx
src/PlaylistFile.cxx
+9
-20
FileSystem.cxx
src/fs/FileSystem.cxx
+13
-0
FileSystem.hxx
src/fs/FileSystem.hxx
+5
-10
No files found.
src/PlaylistFile.cxx
View file @
6caf53d1
...
...
@@ -122,24 +122,6 @@ spl_map_to_fs(const char *name_utf8)
return
path_fs
;
}
/**
* Throw an exception for the current errno.
*/
static
void
ThrowPlaylistErrno
()
{
switch
(
errno
)
{
case
ENOENT
:
throw
PlaylistError
(
PlaylistResult
::
NO_SUCH_LIST
,
"No such playlist"
);
default
:
throw
std
::
system_error
(
std
::
error_code
(
errno
,
std
::
system_category
()),
"Error"
);
}
}
static
bool
LoadPlaylistFileInfo
(
PlaylistInfo
&
info
,
const
Path
parent_path_fs
,
...
...
@@ -392,8 +374,15 @@ spl_rename_internal(Path from_path_fs, Path to_path_fs)
throw
PlaylistError
(
PlaylistResult
::
LIST_EXISTS
,
"Playlist exists already"
);
if
(
!
RenameFile
(
from_path_fs
,
to_path_fs
))
ThrowPlaylistErrno
();
try
{
RenameFile
(
from_path_fs
,
to_path_fs
);
}
catch
(
const
std
::
system_error
&
e
)
{
if
(
IsPathNotFound
(
e
))
throw
PlaylistError
(
PlaylistResult
::
NO_SUCH_LIST
,
"No such playlist"
);
else
throw
;
}
idle_add
(
IDLE_STORED_PLAYLIST
);
}
...
...
src/fs/FileSystem.cxx
View file @
6caf53d1
...
...
@@ -26,6 +26,19 @@
#include <errno.h>
#include <fcntl.h>
void
RenameFile
(
Path
oldpath
,
Path
newpath
)
{
#ifdef WIN32
if
(
!
MoveFileEx
(
oldpath
.
c_str
(),
newpath
.
c_str
(),
MOVEFILE_REPLACE_EXISTING
))
throw
MakeLastError
(
"Failed to rename file"
);
#else
if
(
rename
(
oldpath
.
c_str
(),
newpath
.
c_str
())
<
0
)
throw
MakeErrno
(
"Failed to rename file"
);
#endif
}
AllocatedPath
ReadLink
(
Path
path
)
{
...
...
src/fs/FileSystem.hxx
View file @
6caf53d1
...
...
@@ -63,18 +63,13 @@ OpenFile(Path file, int flags, int mode)
#endif
}
/*
*
/*
* Wrapper for rename() that uses #Path names.
*
* Throws std::system_error on error.
*/
static
inline
bool
RenameFile
(
Path
oldpath
,
Path
newpath
)
{
#ifdef WIN32
return
_trename
(
oldpath
.
c_str
(),
newpath
.
c_str
())
==
0
;
#else
return
rename
(
oldpath
.
c_str
(),
newpath
.
c_str
())
==
0
;
#endif
}
void
RenameFile
(
Path
oldpath
,
Path
newpath
);
#ifndef WIN32
...
...
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