Added --bt-remove-unselected-file option.

Removes the unselected files when download is completed in
BitTorrent. To selecting files, use --select-file option. If it is not
used, all files are assumed to be selected. Please use this option
with care because it will actually remove files from your disk.
This option is default to false.
pull/14/head
Tatsuhiro Tsujikawa 2012-03-25 19:25:43 +09:00
parent 9669bafb7f
commit 8499a47d21
7 changed files with 65 additions and 0 deletions

View File

@ -574,6 +574,16 @@ BitTorrent Specific Options
last SIZE bytes of each file. SIZE can include 'K' or 'M'(1K = 1024,
1M = 1024K). If SIZE is omitted, SIZE=1M is used.
[[aria2_optref_bt_remove_unselected_file]]*--bt-remove-unselected-file*[='true'|'false']::
Removes the unselected files when download is completed in
BitTorrent. To selecting files, use
*<<aria2_optref_select_file, --select-file>>* option. If it is
not used, all files are assumed to be selected. Please use this
option with care because it will actually remove files from your
disk.
Default: 'false'
[[aria2_optref_bt_require_crypto]]*--bt-require-crypto*[='true'|'false']::
If true is given, aria2 doesn't accept and establish connection with legacy
BitTorrent handshake(\19BitTorrent protocol).
@ -1564,6 +1574,7 @@ of URIs. These optional lines must start with white space(s).
* *<<aria2_optref_bt_tracker_connect_timeout, bt-tracker-connect-timeout>>*
* *<<aria2_optref_bt_tracker_interval, bt-tracker-interval>>*
* *<<aria2_optref_bt_tracker_timeout, bt-tracker-timeout>>*
* *<<aria2_optref_bt_remove_unselected_file, bt-remove-unselected-file>>*
* *<<aria2_optref_check_integrity, check-integrity>>*
* *<<aria2_optref_conditional_get, conditional-get>>*
* *<<aria2_optref_connect_timeout, connect-timeout>>*
@ -2833,6 +2844,7 @@ The following options are available for active downloads:
* *<<aria2_optref_bt_max_peers, bt-max-peers>>*
* *<<aria2_optref_bt_request_peer_speed_limit, bt-request-peer-speed-limit>>*
* *<<aria2_optref_bt_remove_unselected_file, bt-remove-unselected-file>>*
* *<<aria2_optref_max_download_limit, max-download-limit>>*
* *<<aria2_optref_max_upload_limit, max-upload-limit>>*

View File

@ -1646,6 +1646,19 @@ OptionHandlerFactory::createOptionHandlers()
op->setChangeOptionForReserved(true);
handlers.push_back(op);
}
{
SharedHandle<OptionHandler> op(new BooleanOptionHandler
(PREF_BT_REMOVE_UNSELECTED_FILE,
TEXT_BT_REMOVE_UNSELECTED_FILE,
A2_V_FALSE,
OptionHandler::OPT_ARG));
op->addTag(TAG_BITTORRENT);
op->setInitialOption(true);
op->setChangeOption(true);
op->setChangeGlobalOption(true);
op->setChangeOptionForReserved(true);
handlers.push_back(op);
}
{
SharedHandle<OptionHandler> op(new UnitNumberOptionHandler
(PREF_BT_REQUEST_PEER_SPEED_LIMIT,

View File

@ -78,6 +78,9 @@
#include "UriListParser.h"
#include "SingletonHolder.h"
#include "Notifier.h"
#ifdef ENABLE_BITTORRENT
# include "bittorrent_helper.h"
#endif // ENABLE_BITTORRENT
namespace aria2 {
@ -359,6 +362,27 @@ public:
static_cast<unsigned long>(nextGroups.size())));
e_->getRequestGroupMan()->insertReservedGroup(0, nextGroups);
}
// For in-memory download (e.g., Magnet URI), the
// FileEntry::getPath() does not return actual file path, so
// we don't remove it.
if(group->getOption()->getAsBool(PREF_BT_REMOVE_UNSELECTED_FILE) &&
!group->inMemoryDownload() &&
dctx->hasAttribute(bittorrent::BITTORRENT)) {
A2_LOG_INFO(fmt(MSG_REMOVING_UNSELECTED_FILE, group->getGID()));
const std::vector<SharedHandle<FileEntry> >& files =
dctx->getFileEntries();
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
files.begin(), eoi = files.end(); i != eoi; ++i) {
if(!(*i)->isRequested()) {
if(File((*i)->getPath()).remove()) {
A2_LOG_INFO(fmt(MSG_FILE_REMOVED, (*i)->getPath().c_str()));
} else {
A2_LOG_INFO(fmt(MSG_FILE_COULD_NOT_REMOVED,
(*i)->getPath().c_str()));
}
}
}
}
} else {
A2_LOG_NOTICE
(fmt(_("Download GID#%lld not complete: %s"),

View File

@ -195,6 +195,9 @@
#define MSG_DIR_TRAVERSAL_DETECTED _("Detected directory traversal directive in %s")
#define MSG_HASH_CHECK_NOT_DONE \
"File has already been downloaded but hash check has not been done yet."
#define MSG_REMOVING_UNSELECTED_FILE _("GID#%lld - Removing unselected file.")
#define MSG_FILE_REMOVED _("File %s removed.")
#define MSG_FILE_COULD_NOT_REMOVED _("File %s could not be removed.")
#define EX_TIME_OUT _("Timeout.")
#define EX_INVALID_CHUNK_SIZE _("Invalid chunk size.")

View File

@ -497,6 +497,9 @@ const Pref* PREF_ON_BT_DOWNLOAD_COMPLETE = makePref("on-bt-download-complete");
const Pref* PREF_BT_TRACKER = makePref("bt-tracker");
// values: string
const Pref* PREF_BT_EXCLUDE_TRACKER = makePref("bt-exclude-tracker");
// values: true | false
const Pref* PREF_BT_REMOVE_UNSELECTED_FILE =
makePref("bt-remove-unselected-file");
/**
* Metalink related preferences

View File

@ -440,6 +440,8 @@ extern const Pref* PREF_ON_BT_DOWNLOAD_COMPLETE;
extern const Pref* PREF_BT_TRACKER;
// values: string
extern const Pref* PREF_BT_EXCLUDE_TRACKER;
// values: true | false
extern const Pref* PREF_BT_REMOVE_UNSELECTED_FILE;
/**
* Metalink related preferences

View File

@ -867,3 +867,11 @@
" file contains a lot of URIs to download.\n" \
" If false is given, aria2 reads all URIs and\n" \
" options at startup.")
#define TEXT_BT_REMOVE_UNSELECTED_FILE \
_(" --bt-remove-unselected-file[=true|false] Removes the unselected files when\n" \
" download is completed in BitTorrent. To\n" \
" selecting files, use --select-file option. If\n" \
" it is not used, all files are assumed to be\n" \
" selected. Please use this option with care\n" \
" because it will actually remove files from\n" \
" your disk.")