diff --git a/src/kaccountsmanager.cpp b/src/kaccountsmanager.cpp --- a/src/kaccountsmanager.cpp +++ b/src/kaccountsmanager.cpp @@ -174,7 +174,7 @@ gapiAccount->addScope(QUrl::fromUserInput(scope)); } - qCDebug(GDRIVE) << "Got account credentials for:" << gapiAccount->accountName() << ", accessToken:" << gapiAccount->accessToken() << ", refreshToken:" << gapiAccount->refreshToken(); + qCDebug(GDRIVE) << "Got account credentials for:" << gapiAccount->accountName() << ", accessToken:" << gapiAccount->accessToken().mid(0, 30).append("...") << ", refreshToken:" << gapiAccount->refreshToken(); return gapiAccount; } diff --git a/src/kio_gdrive.cpp b/src/kio_gdrive.cpp --- a/src/kio_gdrive.cpp +++ b/src/kio_gdrive.cpp @@ -97,7 +97,7 @@ KIOGDrive::Action KIOGDrive::handleError(const KGAPI2::Job &job, const QUrl &url) { - qCDebug(GDRIVE) << "Job status code:" << job.error() << "- message:" << job.errorString(); + qCDebug(GDRIVE) << "Completed job" << (&job) << "status code:" << job.error() << "- message:" << job.errorString(); switch (job.error()) { case KGAPI2::OK: @@ -141,27 +141,32 @@ const auto gdriveUrl = GDriveUrl(url); const QString accountId = gdriveUrl.account(); if (accountId == QLatin1String("new-account")) { + qCDebug(GDRIVE) << "Ignoring fileSystemFreeSpace for new-account"; finished(); return; } - if (!gdriveUrl.isRoot()) { - AboutFetchJob aboutFetch(getAccount(accountId)); - aboutFetch.setFields({ - About::Fields::Kind, - About::Fields::QuotaBytesTotal, - About::Fields::QuotaBytesUsedAggregate - }); - if (runJob(aboutFetch, url, accountId)) { - const AboutPtr about = aboutFetch.aboutData(); - if (about) { - setMetaData(QStringLiteral("total"), QString::number(about->quotaBytesTotal())); - setMetaData(QStringLiteral("available"), QString::number(about->quotaBytesTotal() - about->quotaBytesUsedAggregate())); - finished(); - return; - } + if (gdriveUrl.isRoot()) { + qCDebug(GDRIVE) << "Can't fileSystemFreeSpace for root"; + error(KIO::ERR_CANNOT_STAT, url.toDisplayString()); + return; + } + + qCDebug(GDRIVE) << "Getting fileSystemFreeSpace for" << url; + AboutFetchJob aboutFetch(getAccount(accountId)); + aboutFetch.setFields({ + About::Fields::Kind, + About::Fields::QuotaBytesTotal, + About::Fields::QuotaBytesUsedAggregate + }); + if (runJob(aboutFetch, url, accountId)) { + const AboutPtr about = aboutFetch.aboutData(); + if (about) { + setMetaData(QStringLiteral("total"), QString::number(about->quotaBytesTotal())); + setMetaData(QStringLiteral("available"), QString::number(about->quotaBytesTotal() - about->quotaBytesUsedAggregate())); + finished(); + return; } } - error(KIO::ERR_CANNOT_STAT, url.toDisplayString()); } AccountPtr KIOGDrive::getAccount(const QString &accountName) @@ -340,7 +345,7 @@ QString KIOGDrive::resolveFileIdFromPath(const QString &path, PathFlags flags) { - qCDebug(GDRIVE) << Q_FUNC_INFO << path; + qCDebug(GDRIVE) << "Resolving file ID for" << path; if (path.isEmpty()) { return QString(); @@ -407,6 +412,7 @@ { auto it = m_rootIds.constFind(accountId); if (it == m_rootIds.cend()) { + qCDebug(GDRIVE) << "Getting root ID for" << accountId; AboutFetchJob aboutFetch(getAccount(accountId)); aboutFetch.setFields({About::Fields::Kind, About::Fields::RootFolderId}); QUrl url; @@ -466,7 +472,10 @@ KGAPI2::Drive::File::Fields::LastViewedByMeDate, }); fileFetchJob.setFields(KGAPI2::Drive::FileFetchJob::FieldShorthands::BasicFields + extraFields); - runJob(fileFetchJob, url, accountId); + if (!runJob(fileFetchJob, url, accountId)) { + // runJob called error() + return; + } ObjectsList objects = fileFetchJob.items(); Q_FOREACH (const ObjectPtr &object, objects) { @@ -527,9 +536,9 @@ file->setParents(ParentReferencesList() << parent); FileCreateJob createJob(file, getAccount(accountId)); - runJob(createJob, url, accountId); - - finished(); + if (runJob(createJob, url, accountId)) { + finished(); + } } void KIOGDrive::stat(const QUrl &url) @@ -562,7 +571,10 @@ } FileFetchJob fileFetchJob(fileId, getAccount(accountId)); - runJob(fileFetchJob, url, accountId); + if (!runJob(fileFetchJob, url, accountId)) { + // runJob called error() + return; + } const ObjectsList objects = fileFetchJob.items(); if (objects.count() != 1) { @@ -612,7 +624,10 @@ FileFetchJob fileFetchJob(fileId, getAccount(accountId)); fileFetchJob.setFields({File::Fields::Id, File::Fields::MimeType, File::Fields::ExportLinks, File::Fields::DownloadUrl}); - runJob(fileFetchJob, url, accountId); + if (!runJob(fileFetchJob, url, accountId)) { + // runJob called error() + return; + } const ObjectsList objects = fileFetchJob.items(); if (objects.count() != 1) { @@ -631,7 +646,10 @@ mimeType(file->mimeType()); FileFetchContentJob contentJob(downloadUrl, getAccount(accountId)); - runJob(contentJob, url, accountId); + if (!runJob(contentJob, url, accountId)) { + // runJob called error() + return; + } QByteArray contentData = contentJob.data(); @@ -692,7 +710,7 @@ { KIOGDrive::Action action = KIOGDrive::Fail; Q_FOREVER { - qCDebug(GDRIVE) << "Running job" << (&job) << "with accessToken" << job.account()->accessToken(); + qCDebug(GDRIVE) << "Running job" << (&job) << "with accessToken" << job.account()->accessToken().mid(0, 30).append("..."); QEventLoop eventLoop; QObject::connect(&job, &KGAPI2::Job::finished, &eventLoop, &QEventLoop::quit); @@ -867,7 +885,10 @@ } FileFetchJob sourceFileFetchJob(sourceFileId, getAccount(sourceAccountId)); sourceFileFetchJob.setFields({File::Fields::Id, File::Fields::ModifiedDate, File::Fields::LastViewedByMeDate, File::Fields::Description}); - runJob(sourceFileFetchJob, src, sourceAccountId); + if (!runJob(sourceFileFetchJob, src, sourceAccountId)) { + // runJob called error() + return; + } const ObjectsList objects = sourceFileFetchJob.items(); if (objects.count() != 1) { @@ -899,9 +920,9 @@ destFile->setParents(destParentReferences); FileCopyJob copyJob(sourceFile, destFile, getAccount(sourceAccountId)); - runJob(copyJob, dest, sourceAccountId); - - finished(); + if (runJob(copyJob, dest, sourceAccountId)) { + finished(); + } } void KIOGDrive::del(const QUrl &url, bool isfile) @@ -950,7 +971,10 @@ // child references if (!isfile) { ChildReferenceFetchJob referencesFetch(fileId, getAccount(accountId)); - runJob(referencesFetch, url, accountId); + if (!runJob(referencesFetch, url, accountId)) { + // runJob called error() + return; + } const bool isEmpty = !referencesFetch.items().count(); if (!isEmpty && metaData(QStringLiteral("recurse")) != QLatin1String("true")) { @@ -960,12 +984,10 @@ } FileTrashJob trashJob(fileId, getAccount(accountId)); - runJob(trashJob, url, accountId); - - m_cache.removePath(url.path()); - - finished(); - + if (runJob(trashJob, url, accountId)) { + m_cache.removePath(url.path()); + finished(); + } } void KIOGDrive::rename(const QUrl &src, const QUrl &dest, KIO::JobFlags flags) @@ -1006,7 +1028,10 @@ // We need to fetch ALL, so that we can do update later FileFetchJob sourceFileFetchJob(sourceFileId, getAccount(sourceAccountId)); - runJob(sourceFileFetchJob, src, sourceAccountId); + if (!runJob(sourceFileFetchJob, src, sourceAccountId)) { + // runJob called error() + return; + } const ObjectsList objects = sourceFileFetchJob.items(); if (objects.count() != 1) { @@ -1058,9 +1083,9 @@ FileModifyJob modifyJob(destFile, getAccount(sourceAccountId)); modifyJob.setUpdateModifiedDate(true); - runJob(modifyJob, dest, sourceAccountId); - - finished(); + if (runJob(modifyJob, dest, sourceAccountId)) { + finished(); + } } void KIOGDrive::mimetype(const QUrl &url) @@ -1080,7 +1105,10 @@ FileFetchJob fileFetchJob(fileId, getAccount(accountId)); fileFetchJob.setFields({File::Fields::Id, File::Fields::MimeType}); - runJob(fileFetchJob, url, accountId); + if (!runJob(fileFetchJob, url, accountId)) { + // runJob called error() + return; + } const ObjectsList objects = fileFetchJob.items(); if (objects.count() != 1) {