diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2020-02-15 12:25:37 -0500 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2020-02-18 17:25:04 -0500 |
| commit | 88ef0530001d43be8f18fac43a280169b45db852 (patch) | |
| tree | 0dd2265fae5528e654d780d9bad360e7b82e9456 /src/shared/directoryentry.cpp | |
| parent | 9eeaa88cf5fbed542c05f408982a1492831283ff (diff) | |
error checking in dump()
removed a bunch of "{} saved" in the logs
Diffstat (limited to 'src/shared/directoryentry.cpp')
| -rw-r--r-- | src/shared/directoryentry.cpp | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/shared/directoryentry.cpp b/src/shared/directoryentry.cpp index 394eda7e..6c5ad9ae 100644 --- a/src/shared/directoryentry.cpp +++ b/src/shared/directoryentry.cpp @@ -1685,14 +1685,33 @@ void DirectoryEntry::addFileToList( // fileNameLower has been moved from this point
}
+struct DumpFailed : public std::runtime_error
+{
+ using runtime_error::runtime_error;
+};
+
void DirectoryEntry::dump(const std::wstring& file) const
{
- std::FILE* f = nullptr;
- auto e = _wfopen_s(&f, file.c_str(), L"wb");
+ try
+ {
+ std::FILE* f = nullptr;
+ auto e = _wfopen_s(&f, file.c_str(), L"wb");
+
+ if (e != 0 || !f) {
+ throw DumpFailed(fmt::format(
+ "failed to open, {} ({})", std::strerror(e), e));
+ }
- dump(f, L"Data");
+ Guard g([&]{ std::fclose(f); });
- std::fclose(f);
+ dump(f, L"Data");
+ }
+ catch(DumpFailed& e)
+ {
+ log::error(
+ "failed to write list to '{}': {}",
+ QString::fromStdWString(file).toStdString(), e.what());
+ }
}
void DirectoryEntry::dump(std::FILE* f, const std::wstring& parentPath) const
@@ -1716,7 +1735,12 @@ void DirectoryEntry::dump(std::FILE* f, const std::wstring& parentPath) const const auto line = path + L"\t(" + o.getName() + L")\r\n";
const auto lineu8 = MOShared::ToString(line, true);
- std::fwrite(lineu8.data(), lineu8.size(), 1, f);
+
+ if (std::fwrite(lineu8.data(), lineu8.size(), 1, f) != 1) {
+ const auto e = errno;
+ throw DumpFailed(fmt::format(
+ "failed to write, {} ({})", std::strerror(e), e));
+ }
}
}
|
