From 831bac14718c714f73776304ff1e23a383997146 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 23 Oct 2010 13:43:32 +0000 Subject: [PATCH] 2010-10-23 Tatsuhiro Tsujikawa Fixed the bug that dht.dat file could not be saved. This is because a directory denoting temporary file path is wrongly created and thus aria2 fails to open the file as regular file. * src/DHTAutoSaveCommand.cc --- ChangeLog | 7 +++++++ src/DHTAutoSaveCommand.cc | 17 +++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index e13ec08a..da305b88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-10-23 Tatsuhiro Tsujikawa + + Fixed the bug that dht.dat file could not be saved. This is + because a directory denoting temporary file path is wrongly + created and thus aria2 fails to open the file as regular file. + * src/DHTAutoSaveCommand.cc + 2010-10-22 Tatsuhiro Tsujikawa Enclosed dht.dat path with single quote. diff --git a/src/DHTAutoSaveCommand.cc b/src/DHTAutoSaveCommand.cc index abecaded..7be49920 100644 --- a/src/DHTAutoSaveCommand.cc +++ b/src/DHTAutoSaveCommand.cc @@ -89,9 +89,13 @@ void DHTAutoSaveCommand::save() get(family_ == AF_INET? PREF_DHT_FILE_PATH : PREF_DHT_FILE_PATH6); getLogger()->info("Saving DHT routing table to %s.", dhtFile.c_str()); - std::string tempFile = dhtFile; - tempFile += "__temp"; - File(tempFile).mkdirs(); + 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. + tempFile.remove(); + File(tempFile.getDirname()).mkdirs(); std::vector > nodes; std::vector > buckets; routingTable_->getBuckets(buckets); @@ -109,7 +113,8 @@ void DHTAutoSaveCommand::save() try { { - std::ofstream o(tempFile.c_str(), std::ios::out|std::ios::binary); + std::ofstream o(tempFile.getPath().c_str(), + std::ios::out|std::ios::binary); if(!o) { throw DL_ABORT_EX (StringFormat("Failed to save DHT routing table to %s. cause:%s", @@ -117,9 +122,9 @@ void DHTAutoSaveCommand::save() } serializer.serialize(o); } - if(!File(tempFile).renameTo(dhtFile)) { + if(!tempFile.renameTo(dhtFile)) { getLogger()->error("Cannot move file from %s to %s.", - tempFile.c_str(), dhtFile.c_str()); + tempFile.getPath().c_str(), dhtFile.c_str()); } } catch(RecoverableException& e) { getLogger()->error("Exception caught while saving DHT routing table to %s",