2010-10-23 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

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
pull/1/head
Tatsuhiro Tsujikawa 2010-10-23 13:43:32 +00:00
parent 379ab7dd09
commit 831bac1471
2 changed files with 18 additions and 6 deletions

View File

@ -1,3 +1,10 @@
2010-10-23 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
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 <t-tujikawa@users.sourceforge.net>
Enclosed dht.dat path with single quote.

View File

@ -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<SharedHandle<DHTNode> > nodes;
std::vector<SharedHandle<DHTBucket> > 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",