diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-08-05 22:15:55 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-08-05 22:15:55 +0900 |
| commit | dea7a7969c4be5d4239f7f31e1cc597f0b792784 (patch) | |
| tree | 2e0704631112007cdcaa71d108a552b83a851d45 /src/DHTAutoSaveCommand.cc | |
| parent | f141cd4228018b8699b403bd4e67e8891d27e9c2 (diff) | |
Rewritten DHTRoutingTableSerializer using stdio instead of stream.
Diffstat (limited to 'src/DHTAutoSaveCommand.cc')
| -rw-r--r-- | src/DHTAutoSaveCommand.cc | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/src/DHTAutoSaveCommand.cc b/src/DHTAutoSaveCommand.cc index a252fa66..128b3cfd 100644 --- a/src/DHTAutoSaveCommand.cc +++ b/src/DHTAutoSaveCommand.cc @@ -35,7 +35,6 @@ #include "DHTAutoSaveCommand.h" #include <cstring> -#include <fstream> #include "DHTRoutingTable.h" #include "DHTNode.h" @@ -86,13 +85,14 @@ void DHTAutoSaveCommand::save() get(family_ == AF_INET? PREF_DHT_FILE_PATH : PREF_DHT_FILE_PATH6); A2_LOG_INFO(fmt("Saving DHT routing table to %s.", dhtFile.c_str())); - File tempFile(dhtFile+"__temp"); // Removing tempFile is unnecessary because the file is truncated on // open. But the bug in 1.10.4 creates directory for this path. // Because it is directory, opening directory as file fails. So we // first remove it here. + File tempFile(dhtFile+"__temp"); tempFile.remove(); - File(tempFile.getDirname()).mkdirs(); + + File(File(dhtFile).getDirname()).mkdirs(); std::vector<SharedHandle<DHTNode> > nodes; std::vector<SharedHandle<DHTBucket> > buckets; routingTable_->getBuckets(buckets); @@ -109,20 +109,7 @@ void DHTAutoSaveCommand::save() serializer.setNodes(nodes); try { - { - std::ofstream o(tempFile.getPath().c_str(), - std::ios::out|std::ios::binary); - if(!o) { - throw DL_ABORT_EX - (fmt("Failed to save DHT routing table to %s.", - dhtFile.c_str())); - } - serializer.serialize(o); - } - if(!tempFile.renameTo(dhtFile)) { - A2_LOG_ERROR(fmt("Cannot move file from %s to %s.", - tempFile.getPath().c_str(), dhtFile.c_str())); - } + serializer.serialize(dhtFile); } catch(RecoverableException& e) { A2_LOG_ERROR_EX(fmt("Exception caught while saving DHT routing table to %s", dhtFile.c_str()), |
