system/FmtError: new library
Replaces the Format*() functions in system/Error.hxx.
This commit is contained in:
@@ -18,7 +18,8 @@
|
||||
*/
|
||||
|
||||
#include "DirectoryReader.hxx"
|
||||
#include "system/Error.hxx"
|
||||
#include "lib/fmt/PathFormatter.hxx"
|
||||
#include "system/FmtError.hxx"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -28,7 +29,7 @@ DirectoryReader::DirectoryReader(Path dir)
|
||||
:handle(FindFirstFile(MakeWildcardPath(dir.c_str()), &data))
|
||||
{
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
throw FormatLastError("Failed to open %s", dir.c_str());
|
||||
throw FmtLastError("Failed to open {}", dir);
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -37,7 +38,7 @@ DirectoryReader::DirectoryReader(Path dir)
|
||||
:dirp(opendir(dir.c_str()))
|
||||
{
|
||||
if (dirp == nullptr)
|
||||
throw FormatErrno("Failed to open %s", dir.c_str());
|
||||
throw FmtErrno("Failed to open {}", dir);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -21,7 +21,8 @@
|
||||
#define MPD_FS_FILE_INFO_HXX
|
||||
|
||||
#include "Path.hxx"
|
||||
#include "system/Error.hxx"
|
||||
#include "lib/fmt/PathFormatter.hxx"
|
||||
#include "system/FmtError.hxx"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "time/FileTime.hxx"
|
||||
@@ -49,11 +50,9 @@ public:
|
||||
FileInfo(Path path, bool follow_symlinks=true) {
|
||||
if (!GetFileInfo(path, *this, follow_symlinks)) {
|
||||
#ifdef _WIN32
|
||||
throw FormatLastError("Failed to access %s",
|
||||
path.ToUTF8().c_str());
|
||||
throw FmtLastError("Failed to access {}", path);
|
||||
#else
|
||||
throw FormatErrno("Failed to access %s",
|
||||
path.ToUTF8().c_str());
|
||||
throw FmtErrno("Failed to access {}", path);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,8 @@
|
||||
#include "FileSystem.hxx"
|
||||
#include "AllocatedPath.hxx"
|
||||
#include "Limits.hxx"
|
||||
#include "system/Error.hxx"
|
||||
#include "lib/fmt/PathFormatter.hxx"
|
||||
#include "system/FmtError.hxx"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <handleapi.h> // for CloseHandle()
|
||||
@@ -73,13 +74,13 @@ TruncateFile(Path path)
|
||||
TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL,
|
||||
nullptr);
|
||||
if (h == INVALID_HANDLE_VALUE)
|
||||
throw FormatLastError("Failed to truncate %s", path.c_str());
|
||||
throw FmtLastError("Failed to truncate {}", path);
|
||||
|
||||
CloseHandle(h);
|
||||
#else
|
||||
UniqueFileDescriptor fd;
|
||||
if (!fd.Open(path.c_str(), O_WRONLY|O_TRUNC))
|
||||
throw FormatErrno("Failed to truncate %s", path.c_str());
|
||||
throw FmtErrno("Failed to truncate {}", path);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -88,9 +89,9 @@ RemoveFile(Path path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!DeleteFile(path.c_str()))
|
||||
throw FormatLastError("Failed to delete %s", path.c_str());
|
||||
throw FmtLastError("Failed to delete {}", path);
|
||||
#else
|
||||
if (unlink(path.c_str()) < 0)
|
||||
throw FormatErrno("Failed to delete %s", path.c_str());
|
||||
throw FmtErrno("Failed to delete {}", path);
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user