summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/Storages/AvatarFileStorage.cpp')
-rw-r--r--Swift/Controllers/Storages/AvatarFileStorage.cpp31
1 files changed, 20 insertions, 11 deletions
diff --git a/Swift/Controllers/Storages/AvatarFileStorage.cpp b/Swift/Controllers/Storages/AvatarFileStorage.cpp
index a103920..9d9b9ea 100644
--- a/Swift/Controllers/Storages/AvatarFileStorage.cpp
+++ b/Swift/Controllers/Storages/AvatarFileStorage.cpp
@@ -1,3 +1,3 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
@@ -8,4 +8,2 @@
-#include <iostream>
-
#include <boost/filesystem.hpp>
@@ -13,2 +11,3 @@
+#include <Swiften/Base/Log.h>
#include <Swiften/Base/String.h>
@@ -33,3 +32,3 @@ AvatarFileStorage::AvatarFileStorage(const boost::filesystem::path& avatarsDir,
else if (!r.first.empty() || !r.second.empty()) {
- std::cerr << "Invalid entry in avatars file: " << r.second << std::endl;
+ SWIFT_LOG(error) << "Invalid entry in avatars file: " << r.second << std::endl;
}
@@ -39,3 +38,3 @@ AvatarFileStorage::AvatarFileStorage(const boost::filesystem::path& avatarsDir,
catch (...) {
- std::cerr << "Error reading avatars file" << std::endl;
+ SWIFT_LOG(error) << "Error reading avatars file" << std::endl;
}
@@ -57,8 +56,13 @@ void AvatarFileStorage::addAvatar(const std::string& hash, const ByteArray& avat
catch (const boost::filesystem::filesystem_error& e) {
- std::cerr << "ERROR: " << e.what() << std::endl;
+ SWIFT_LOG(error) << "filesystem error: " << e.what() << std::endl;
}
}
- boost::filesystem::ofstream file(avatarPath, boost::filesystem::ofstream::binary|boost::filesystem::ofstream::out);
- file.write(reinterpret_cast<const char*>(vecptr(avatar)), static_cast<std::streamsize>(avatar.size()));
- file.close();
+
+ try {
+ boost::filesystem::ofstream file(avatarPath, boost::filesystem::ofstream::binary|boost::filesystem::ofstream::out);
+ file.write(reinterpret_cast<const char*>(vecptr(avatar)), static_cast<std::streamsize>(avatar.size()));
+ }
+ catch (const boost::filesystem::filesystem_error& e) {
+ SWIFT_LOG(error) << "filesystem error: " << e.what() << std::endl;
+ }
}
@@ -71,3 +75,8 @@ ByteArray AvatarFileStorage::getAvatar(const std::string& hash) const {
ByteArray data;
- readByteArrayFromFile(data, getAvatarPath(hash));
+ try {
+ readByteArrayFromFile(data, getAvatarPath(hash));
+ }
+ catch (const boost::filesystem::filesystem_error& e) {
+ SWIFT_LOG(error) << "filesystem error: " << e.what() << std::endl;
+ }
return data;
@@ -100,3 +109,3 @@ void AvatarFileStorage::saveJIDAvatars() {
catch (...) {
- std::cerr << "Error writing avatars file" << std::endl;
+ SWIFT_LOG(error) << "Error writing avatars file" << std::endl;
}