diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2015-11-10 23:02:21 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2015-11-10 23:02:21 +0900 |
| commit | 269520ee69e2306eaf792ccff916ba5486d2bb5f (patch) | |
| tree | ab31cea457c60a3a351073e6bf74cbc89ca37139 /src/SessionSerializer.cc | |
| parent | 5ccd5b6953c95986407a735a41e8c36cf05944d1 (diff) | |
Don't write control file if content is not changed from previous one
This is desirable so that we don't have to wake up disk if control
file is not changed, and it is not have to be written again. We use
the same method (SHA1 hash) to check the content is the same. The
limitation is the hash is stored in memory, so we have to write the
first time in each session.
See GH-382
Diffstat (limited to 'src/SessionSerializer.cc')
| -rw-r--r-- | src/SessionSerializer.cc | 76 |
1 files changed, 1 insertions, 75 deletions
diff --git a/src/SessionSerializer.cc b/src/SessionSerializer.cc index f2d12116..7dd91aef 100644 --- a/src/SessionSerializer.cc +++ b/src/SessionSerializer.cc @@ -53,7 +53,7 @@ #include "BufferedFile.h" #include "OptionParser.h" #include "OptionHandler.h" -#include "MessageDigest.h" +#include "SHA1IOFile.h" #if HAVE_ZLIB #include "GZipFile.h" @@ -327,80 +327,6 @@ bool SessionSerializer::save(IOFile& fp) const return true; } -namespace { -// Class to calculate SHA1 hash value for data written into this -// object. No file I/O is done in this class. -class SHA1IOFile : public IOFile { -public: - SHA1IOFile() - : sha1_(MessageDigest::sha1()) - {} - - std::string digest() - { - return sha1_->digest(); - } -protected: - virtual size_t onRead(void* ptr, size_t count) CXX11_OVERRIDE - { - assert(0); - return 0; - } - - virtual size_t onWrite(const void* ptr, size_t count) CXX11_OVERRIDE - { - sha1_->update(ptr, count); - - return count; - } - - virtual char* onGets(char* s, int size) CXX11_OVERRIDE - { - assert(0); - return nullptr; - } - - virtual int onVprintf(const char* format, va_list va) CXX11_OVERRIDE - { - assert(0); - return -1; - } - - virtual int onFlush() CXX11_OVERRIDE - { - return 0; - } - - virtual int onClose() CXX11_OVERRIDE - { - return 0; - } - - virtual bool onSupportsColor() CXX11_OVERRIDE - { - return false; - } - - virtual bool isError() const CXX11_OVERRIDE - { - return false; - } - - virtual bool isEOF() const CXX11_OVERRIDE - { - return false; - } - - virtual bool isOpen() const CXX11_OVERRIDE - { - return true; - } - -private: - std::unique_ptr<MessageDigest> sha1_; -}; -} // namespace - std::string SessionSerializer::calculateHash() const { SHA1IOFile sha1io; |
