diff --git a/src/PlaylistFile.cxx b/src/PlaylistFile.cxx index 3c29d1003..99d343b0d 100644 --- a/src/PlaylistFile.cxx +++ b/src/PlaylistFile.cxx @@ -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); } diff --git a/src/fs/FileSystem.cxx b/src/fs/FileSystem.cxx index 49a1072d7..d7718ba26 100644 --- a/src/fs/FileSystem.cxx +++ b/src/fs/FileSystem.cxx @@ -26,6 +26,19 @@ #include #include +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) { diff --git a/src/fs/FileSystem.hxx b/src/fs/FileSystem.hxx index 83261a8ec..92e3c3349 100644 --- a/src/fs/FileSystem.hxx +++ b/src/fs/FileSystem.hxx @@ -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