# HG changeset patch # User Sebastien Jodogne # Date 1474019597 -7200 # Node ID e9e6ffbf0fd59e7aecd27ca41ac4336fa9dc32bd # Parent 6306060977983dd1e484615fd62bdf8283df3203 improved logging in FilesystemStorage diff -r 630606097798 -r e9e6ffbf0fd5 Core/FileStorage/FilesystemStorage.cpp --- a/Core/FileStorage/FilesystemStorage.cpp Fri Sep 16 09:18:35 2016 +0200 +++ b/Core/FileStorage/FilesystemStorage.cpp Fri Sep 16 11:53:17 2016 +0200 @@ -86,11 +86,37 @@ Toolbox::MakeDirectory(root); } + + + static const char* GetDescriptionInternal(FileContentType content) + { + // This function is for logging only (internal use), a more + // fully-featured version is available in ServerEnumerations.cpp + switch (content) + { + case FileContentType_Unknown: + return "Unknown"; + + case FileContentType_Dicom: + return "DICOM"; + + case FileContentType_DicomAsJson: + return "JSON summary of DICOM"; + + default: + return "User-defined"; + } + } + + void FilesystemStorage::Create(const std::string& uuid, const void* content, size_t size, - FileContentType /*type*/) + FileContentType type) { + LOG(INFO) << "Creating attachment \"" << uuid << "\" of \"" << GetDescriptionInternal(type) + << "\" type (size: " << (size / (1024 * 1024) + 1) << "MB)"; + boost::filesystem::path path; path = GetPath(uuid); @@ -117,31 +143,17 @@ } } - boost::filesystem::ofstream f; - f.open(path, std::ofstream::out | std::ios::binary); - if (!f.good()) - { - throw OrthancException(ErrorCode_FileStorageCannotWrite); - } - - if (size != 0) - { - f.write(static_cast(content), size); - if (!f.good()) - { - f.close(); - throw OrthancException(ErrorCode_FileStorageCannotWrite); - } - } - - f.close(); + Toolbox::WriteFile(content, size, path.string()); } void FilesystemStorage::Read(std::string& content, const std::string& uuid, - FileContentType /*type*/) + FileContentType type) { + LOG(INFO) << "Reading attachment \"" << uuid << "\" of \"" << GetDescriptionInternal(type) + << "\" content type"; + content.clear(); Toolbox::ReadFile(content, GetPath(uuid).string()); } @@ -213,9 +225,7 @@ void FilesystemStorage::Remove(const std::string& uuid, FileContentType /*type*/) { -#if ORTHANC_ENABLE_GOOGLE_LOG == 1 - LOG(INFO) << "Deleting file " << uuid; -#endif + LOG(INFO) << "Deleting attachment \"" << uuid << "\""; namespace fs = boost::filesystem; diff -r 630606097798 -r e9e6ffbf0fd5 Core/Toolbox.cpp --- a/Core/Toolbox.cpp Fri Sep 16 09:18:35 2016 +0200 +++ b/Core/Toolbox.cpp Fri Sep 16 11:53:17 2016 +0200 @@ -312,7 +312,7 @@ const std::string& path) { boost::filesystem::ofstream f; - f.open(path, std::ofstream::binary); + f.open(path, std::ofstream::out | std::ofstream::binary); if (!f.good()) { throw OrthancException(ErrorCode_CannotWriteFile); @@ -321,6 +321,12 @@ if (size != 0) { f.write(reinterpret_cast(content), size); + + if (!f.good()) + { + f.close(); + throw OrthancException(ErrorCode_FileStorageCannotWrite); + } } f.close();