diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-09-12 09:26:22 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-09-12 09:26:22 (GMT) |
commit | 6fc3f55d26748c277ce5f90d2d1cf89ed777a46e (patch) | |
tree | 00d8d6fde61cc816ef67173a398e6c98b1e65c25 /Swiften/Avatars | |
parent | 88a6da65a7b941191ce3836009af9a0d68b89f77 (diff) | |
download | swift-contrib-6fc3f55d26748c277ce5f90d2d1cf89ed777a46e.zip swift-contrib-6fc3f55d26748c277ce5f90d2d1cf89ed777a46e.tar.bz2 |
Create avatar cache dir lazily.
Diffstat (limited to 'Swiften/Avatars')
-rw-r--r-- | Swiften/Avatars/AvatarFileStorage.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/Swiften/Avatars/AvatarFileStorage.cpp b/Swiften/Avatars/AvatarFileStorage.cpp index b6630e9..f76adee 100644 --- a/Swiften/Avatars/AvatarFileStorage.cpp +++ b/Swiften/Avatars/AvatarFileStorage.cpp @@ -12,12 +12,6 @@ namespace Swift { AvatarFileStorage::AvatarFileStorage(const boost::filesystem::path& path) : path_(path) { - try { - boost::filesystem::create_directories(path_); - } - catch (const boost::filesystem::filesystem_error& e) { - std::cerr << "ERROR: " << e.what() << std::endl; - } } bool AvatarFileStorage::hasAvatar(const String& hash) const { @@ -25,7 +19,16 @@ bool AvatarFileStorage::hasAvatar(const String& hash) const { } void AvatarFileStorage::addAvatar(const String& hash, const ByteArray& avatar) { - boost::filesystem::ofstream file(getAvatarPath(hash), boost::filesystem::ofstream::binary|boost::filesystem::ofstream::out); + boost::filesystem::path avatarPath = getAvatarPath(hash); + if (!boost::filesystem::exists(avatarPath.parent_path())) { + try { + boost::filesystem::create_directories(avatarPath.parent_path()); + } + catch (const boost::filesystem::filesystem_error& e) { + std::cerr << "ERROR: " << e.what() << std::endl; + } + } + boost::filesystem::ofstream file(avatarPath, boost::filesystem::ofstream::binary|boost::filesystem::ofstream::out); file.write(avatar.getData(), avatar.getSize()); file.close(); } |