[network/kio-s3] /: Port to WorkerBase

Elvis Angelaccio null at kde.org
Tue Sep 13 23:30:20 BST 2022


Git commit 42562a41af3849bbc029cfa87efc39e356157a05 by Elvis Angelaccio.
Committed on 13/09/2022 at 22:23.
Pushed by elvisangelaccio into branch 'master'.

Port to WorkerBase

WorkerBase requires KIO 5.96. It seems that this version of KF5 brings in the
QT_NO_CAST_FROM_ASCII macro, so this commit also fixes a bunch of
compilation errors with QStrings.

M  +2    -2    CMakeLists.txt
M  +4    -4    README.md
M  +1    -1    autotests/s3urltest.cpp
M  +1    -0    doc/CMakeLists.txt
M  +1    -1    doc/index.docbook
M  +28   -28   src/kio_s3.cpp
M  +16   -16   src/kio_s3.h
M  +8    -7    src/s3backend.cpp
M  +3    -3    src/s3backend.h

https://invent.kde.org/network/kio-s3/commit/42562a41af3849bbc029cfa87efc39e356157a05

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d9baaec..0f7804e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,7 +7,7 @@ set(KIO_S3_VERSION 0.9.70)
 project(kio-s3 VERSION ${KIO_S3_VERSION})
 
 set(QT_MIN_VERSION 5.15.0)
-set(KF5_MIN_VERSION 5.71.0)
+set(KF5_MIN_VERSION 5.96.0)
 
 find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
 set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
@@ -35,7 +35,7 @@ find_package(AWSSDK REQUIRED COMPONENTS
 set_package_properties(AWSSDK PROPERTIES DESCRIPTION "the AWS SDK for C++"
     URL "https://github.com/aws/aws-sdk-cpp"
     TYPE REQUIRED
-    PURPOSE "Needed to build the S3 kioslave")
+    PURPOSE "Needed to build the S3 KIO worker")
 
 find_package(Qt5Test QUIET)
 set_package_properties(Qt5Test PROPERTIES
diff --git a/README.md b/README.md
index 951e7f8..f9afff8 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
 KIO S3
 ======
 
-A kio slave for Amazon Simple Storage Service (Amazon S3): https://aws.amazon.com/s3/
+A KIO worker for Amazon Simple Storage Service (Amazon S3): https://aws.amazon.com/s3/
 
 S3 is an object store. It has buckets and objects.
 Buckets contain objects, and objects are made of data (usually a file) and metadata (information about the data).
@@ -14,8 +14,8 @@ Buckets contain objects, and objects are made of data (usually a file) and metad
 BUILDING
 ========
 
-The Amazon AWS SDK for C++ is required to build this slave: https://github.com/aws/aws-sdk-cpp
-The slave requires the `core` and `s3` SDK components.
+The Amazon AWS SDK for C++ is required to build this project: https://github.com/aws/aws-sdk-cpp
+In particular the `core` and `s3` SDK components are required.
 
 USAGE
 =====
@@ -23,7 +23,7 @@ USAGE
 1. Configure AWS credentials and region: https://docs.aws.amazon.com/credref/latest/refdocs/overview.html
 2. Run `dolphin s3://`.
 
-The slave supports S3 URIs with the following format:
+The worker supports S3 URIs with the following format:
 
     s3://mybucket/mykey
 
diff --git a/autotests/s3urltest.cpp b/autotests/s3urltest.cpp
index 6fd3efe..d12eb98 100644
--- a/autotests/s3urltest.cpp
+++ b/autotests/s3urltest.cpp
@@ -28,7 +28,7 @@ void S3UrlTest::testS3Url_data()
     QTest::addColumn<QString>("expectedPrefix");
 
     QTest::newRow("root url")
-            << QUrl("s3:")
+            << QUrl(QStringLiteral("s3:"))
             << false
             << false
             << QString()
diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt
index 2850108..6750182 100644
--- a/doc/CMakeLists.txt
+++ b/doc/CMakeLists.txt
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # SPDX-FileCopyrightText: 2020 Elvis Angelaccio <elvis.angelaccio at kde.org>
 
+# TODO: what's the KF6 equivalent for kioslave5?
 kdoctools_create_handbook(index.docbook
     INSTALL_DESTINATION ${KDE_INSTALL_DOCBUNDLEDIR}/en
     SUBDIR kioslave5/s3)
diff --git a/doc/index.docbook b/doc/index.docbook
index ede580d..6bc3003 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -30,7 +30,7 @@
 
 <para>KIO S3 allows you to list Amazon S3 buckets and objects, to upload files and folders to a bucket and to delete objects from a bucket. You can also copy folders or objects within S3, as well as move or rename objects.</para>
 
-<para>You can use the s3 kioslave like this:</para>
+<para>You can use the s3 KIO worker like this:</para>
 <para><userinput>s3://</userinput> or <userinput>s3://<replaceable>mybucket/mykey</replaceable></userinput>.</para>
 
 <para>The first URL shows all your S3 buckets.</para>
diff --git a/src/kio_s3.cpp b/src/kio_s3.cpp
index bc832e0..1f10bb1 100644
--- a/src/kio_s3.cpp
+++ b/src/kio_s3.cpp
@@ -11,7 +11,7 @@
 class KIOPluginForMetaData : public QObject
 {
     Q_OBJECT
-    Q_PLUGIN_METADATA(IID "org.kde.kio.slave.s3" FILE "s3.json")
+    Q_PLUGIN_METADATA(IID "org.kde.kio.worker.s3" FILE "s3.json")
 };
 
 extern "C"
@@ -25,77 +25,77 @@ int Q_DECL_EXPORT kdemain(int argc, char **argv)
         exit(-1);
     }
 
-    S3Slave slave(argv[1], argv[2], argv[3]);
+    S3Worker worker(argv[1], argv[2], argv[3]);
     qCDebug(S3) << "Starting kio_s3...";
-    slave.dispatchLoop();
+    worker.dispatchLoop();
 
     return 0;
 }
 
-S3Slave::S3Slave(const QByteArray &protocol, const QByteArray &pool_socket, const QByteArray &app_socket)
-    : SlaveBase("s3", pool_socket, app_socket)
+S3Worker::S3Worker(const QByteArray &protocol, const QByteArray &pool_socket, const QByteArray &app_socket)
+    : WorkerBase("s3", pool_socket, app_socket)
 {
     Q_UNUSED(protocol)
     qCDebug(S3) << "kio_s3 ready.";
 }
 
-S3Slave::~S3Slave()
+S3Worker::~S3Worker()
 {
     qCDebug(S3) << "kio_s3 ended.";
 }
 
-void S3Slave::listDir(const QUrl &url)
+KIO::WorkerResult S3Worker::listDir(const QUrl &url)
 {
-    finalize(d->listDir(url));
+    return finalize(d->listDir(url));
 }
 
-void S3Slave::stat(const QUrl &url)
+KIO::WorkerResult S3Worker::stat(const QUrl &url)
 {
-    finalize(d->stat(url));
+    return finalize(d->stat(url));
 }
 
-void S3Slave::mimetype(const QUrl &url)
+KIO::WorkerResult S3Worker::mimetype(const QUrl &url)
 {
-    finalize(d->mimetype(url));
+    return finalize(d->mimetype(url));
 }
 
-void S3Slave::get(const QUrl &url)
+KIO::WorkerResult S3Worker::get(const QUrl &url)
 {
-    finalize(d->get(url));
+    return finalize(d->get(url));
 }
 
-void S3Slave::put(const QUrl &url, int permissions, KIO::JobFlags flags)
+KIO::WorkerResult S3Worker::put(const QUrl &url, int permissions, KIO::JobFlags flags)
 {
-    finalize(d->put(url, permissions, flags));
+    return finalize(d->put(url, permissions, flags));
 }
 
-void S3Slave::copy(const QUrl &src, const QUrl &dest, int permissions, KIO::JobFlags flags)
+KIO::WorkerResult S3Worker::copy(const QUrl &src, const QUrl &dest, int permissions, KIO::JobFlags flags)
 {
-    finalize(d->copy(src, dest, permissions, flags));
+    return finalize(d->copy(src, dest, permissions, flags));
 }
 
-void S3Slave::mkdir(const QUrl &url, int permissions)
+KIO::WorkerResult S3Worker::mkdir(const QUrl &url, int permissions)
 {
-    finalize(d->mkdir(url, permissions));
+    return finalize(d->mkdir(url, permissions));
 }
 
-void S3Slave::del(const QUrl &url, bool isfile)
+KIO::WorkerResult S3Worker::del(const QUrl &url, bool isfile)
 {
-    finalize(d->del(url, isfile));
+    return finalize(d->del(url, isfile));
 }
 
-void S3Slave::rename(const QUrl &src, const QUrl &dest, KIO::JobFlags flags)
+KIO::WorkerResult S3Worker::rename(const QUrl &src, const QUrl &dest, KIO::JobFlags flags)
 {
-    finalize(d->rename(src, dest, flags));
+    return finalize(d->rename(src, dest, flags));
 }
 
-void S3Slave::finalize(const S3Backend::Result &result)
+KIO::WorkerResult S3Worker::finalize(const S3Backend::Result &result)
 {
     if (result.exitCode > 0) {
-        error(result.exitCode, result.errorMessage);
-    } else {
-        finished();
+        return KIO::WorkerResult::fail(result.exitCode, result.errorMessage);
     }
+
+    return KIO::WorkerResult::pass();
 }
 
 #include "kio_s3.moc"
diff --git a/src/kio_s3.h b/src/kio_s3.h
index 3d867ff..da58d31 100644
--- a/src/kio_s3.h
+++ b/src/kio_s3.h
@@ -8,33 +8,33 @@
 
 #include "s3backend.h"
 
-#include <KIO/SlaveBase>
+#include <KIO/WorkerBase>
 
 #include <QUrl>
 
-class S3Slave : public KIO::SlaveBase
+class S3Worker : public KIO::WorkerBase
 {
 public:
 
-    S3Slave(const QByteArray &protocol,
+    S3Worker(const QByteArray &protocol,
             const QByteArray &pool_socket,
             const QByteArray &app_socket);
-    ~S3Slave() override;
-
-    void listDir(const QUrl &url) override;
-    void stat(const QUrl &url) override;
-    void mimetype(const QUrl &url) override;
-    void get(const QUrl &url) override;
-    void put(const QUrl &url, int permissions, KIO::JobFlags flags) override;
-    void copy(const QUrl &src, const QUrl &dest, int permissions, KIO::JobFlags flags) override;
-    void mkdir(const QUrl &url, int permissions) override;
-    void del(const QUrl &url, bool isfile) override;
-    void rename(const QUrl &src, const QUrl &dest, KIO::JobFlags flags) override;
+    ~S3Worker() override;
+
+    KIO::WorkerResult listDir(const QUrl &url) override;
+    KIO::WorkerResult stat(const QUrl &url) override;
+    KIO::WorkerResult mimetype(const QUrl &url) override;
+    KIO::WorkerResult get(const QUrl &url) override;
+    KIO::WorkerResult put(const QUrl &url, int permissions, KIO::JobFlags flags) override;
+    KIO::WorkerResult copy(const QUrl &src, const QUrl &dest, int permissions, KIO::JobFlags flags) override;
+    KIO::WorkerResult mkdir(const QUrl &url, int permissions) override;
+    KIO::WorkerResult del(const QUrl &url, bool isfile) override;
+    KIO::WorkerResult rename(const QUrl &src, const QUrl &dest, KIO::JobFlags flags) override;
 
 private:
-    Q_DISABLE_COPY(S3Slave)
+    Q_DISABLE_COPY(S3Worker)
 
-    void finalize(const S3Backend::Result &result);
+    KIO::WorkerResult finalize(const S3Backend::Result &result);
 
     QScopedPointer<S3Backend> d { new S3Backend(this) };
 };
diff --git a/src/s3backend.cpp b/src/s3backend.cpp
index 5d8722b..dce29db 100644
--- a/src/s3backend.cpp
+++ b/src/s3backend.cpp
@@ -28,14 +28,14 @@ static S3Backend::Result finished() {
 
 static S3Backend::Result invalidUrlError() {
     static const S3Backend::Result s_invalidUrlError = {
-        KIO::ERR_SLAVE_DEFINED,
-        xi18nc("@info", "Invalid S3 URI, bucket name is missing from the host.<nl/>A valid S3 URI must be written in the form: <link>%1</link>", "s3://bucket/key")
+        KIO::ERR_WORKER_DEFINED,
+        xi18nc("@info", "Invalid S3 URI, bucket name is missing from the host.<nl/>A valid S3 URI must be written in the form: <link>s3://bucket/key</link>")
     };
 
     return s_invalidUrlError;
 }
 
-S3Backend::S3Backend(S3Slave *q)
+S3Backend::S3Backend(S3Worker *q)
     : q(q)
 {
     Aws::SDKOptions options;
@@ -308,7 +308,7 @@ S3Backend::Result S3Backend::copy(const QUrl &src, const QUrl &dest, int permiss
     auto copyObjectOutcome = client.CopyObject(request);
     if (!copyObjectOutcome.IsSuccess()) {
         qCDebug(S3) << "Could not copy" << src << "to" << dest << "- " << copyObjectOutcome.GetError().GetMessage().c_str();
-        return {KIO::ERR_SLAVE_DEFINED, xi18nc("@info", "Could not copy <link>%1</link> to <link>%2</link>", src.toDisplayString(), dest.toDisplayString())};
+        return {KIO::ERR_WORKER_DEFINED, xi18nc("@info", "Could not copy <link>%1</link> to <link>%2</link>", src.toDisplayString(), dest.toDisplayString())};
     }
 
     return finished();
@@ -420,10 +420,11 @@ void S3Backend::listBucket(const QString &bucketName)
         const auto objects = listObjectsOutcome.GetResult().GetContents();
         for (const auto &object : objects) {
             KIO::UDSEntry entry;
+            const auto objectKey = QString::fromUtf8(object.GetKey().c_str());
             entry.reserve(6);
-            entry.fastInsert(KIO::UDSEntry::UDS_NAME, object.GetKey().c_str());
-            entry.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, object.GetKey().c_str());
-            entry.fastInsert(KIO::UDSEntry::UDS_URL, QStringLiteral("s3://%1/%2").arg(bucketName, object.GetKey().c_str()));
+            entry.fastInsert(KIO::UDSEntry::UDS_NAME, objectKey);
+            entry.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, objectKey);
+            entry.fastInsert(KIO::UDSEntry::UDS_URL, QStringLiteral("s3://%1/%2").arg(bucketName, objectKey));
             entry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG);
             entry.fastInsert(KIO::UDSEntry::UDS_SIZE, object.GetSize());
             entry.fastInsert(KIO::UDSEntry::UDS_ACCESS, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH );
diff --git a/src/s3backend.h b/src/s3backend.h
index a23a335..00ed5bd 100644
--- a/src/s3backend.h
+++ b/src/s3backend.h
@@ -14,7 +14,7 @@
 
 #include <aws/s3/S3Client.h>
 
-class S3Slave;
+class S3Worker;
 
 class S3Backend
 {
@@ -27,7 +27,7 @@ struct Result {
     QString errorMessage;
 };
 
-    S3Backend(S3Slave *q);
+    S3Backend(S3Worker *q);
 
     Q_REQUIRED_RESULT Result listDir(const QUrl &url);
     Q_REQUIRED_RESULT Result stat(const QUrl &url);
@@ -55,7 +55,7 @@ private:
     QString contentType(const S3Url &s3url);
 
     QByteArray m_configProfileName;    // This must be passed to the S3Client objects to get the proper region from ~/.aws/config
-    S3Slave *q = nullptr;
+    S3Worker *q = nullptr;
 };
 
 #endif // S3BACKEND_H



More information about the kde-doc-english mailing list