From 83f4bced07909fb553c11c860816aa6db3de9615 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 3 Jun 2014 23:09:28 +0900 Subject: [PATCH] Fix assertion failure when dir option of paused HTTP/FTP download is changed When the directory is changed via aria2.changeOption RPC method, we directly change first FileEntry's path using FileEntry::setPath(). If there is no PREF_OUT option is given, basically file name is unknown, so we just set empty string and let the next run determine the correct file name and new directory is applied there. But previous code does not reset length property of FileEntry, so the unexpected code path is taken when unpaused and its path expects path is not empty string. This commit fixes this issue by setting length to 0 using FileEntry::setLength(). --- src/RpcMethodImpl.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc index 91d5a2ed..e7ef98c0 100644 --- a/src/RpcMethodImpl.cc +++ b/src/RpcMethodImpl.cc @@ -1478,9 +1478,18 @@ void changeOption && !dctx->hasAttribute(CTX_ATTR_BT) #endif // ENABLE_BITTORRENT ) { - dctx->getFirstFileEntry()->setPath - (grOption->blank(PREF_OUT) ? A2STR::NIL : - util::applyDir(grOption->get(PREF_DIR), grOption->get(PREF_OUT))); + + auto& fileEntry = dctx->getFirstFileEntry(); + + if(grOption->blank(PREF_OUT)) { + // We need to reset length to 0, so that we pretend that file + // name is unknown and it should be determined at next run. + fileEntry->setLength(0); + fileEntry->setPath(A2STR::NIL); + } else { + fileEntry->setPath + (util::applyDir(grOption->get(PREF_DIR), grOption->get(PREF_OUT))); + } } } #ifdef ENABLE_BITTORRENT