Create non-existing path in setLocationAction()

When using qbittorrent-nox it is not always possible to manually create
the target path for torrent moving. This commit allows automatic path
creation. It also allows to display error messages in the
'Set location' window.
This commit is contained in:
Goshik
2018-06-08 09:37:34 +03:00
committed by sledgehammer999
parent 2972e1596d
commit bfad14d552
3 changed files with 19 additions and 6 deletions

View File

@@ -737,9 +737,16 @@ void TorrentsController::setLocationAction()
const QStringList hashes {params()["hashes"].split("|")};
const QString newLocation {params()["location"].trimmed()};
// check if the location exists
if (newLocation.isEmpty() || !QDir(newLocation).exists())
return;
if (newLocation.isEmpty())
throw APIError(APIErrorType::BadParams, tr("Save path is empty"));
// try to create the location if it does not exist
if (!QDir(newLocation).mkpath("."))
throw APIError(APIErrorType::Conflict, tr("Cannot make save path"));
// check permissions
if (!QFileInfo(newLocation).isWritable())
throw APIError(APIErrorType::AccessDenied, tr("Cannot write to directory"));
applyToTorrents(hashes, [newLocation](BitTorrent::TorrentHandle *torrent)
{