Create debug archive on client side
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 3 Jan 2024 09:16:10 +0000 (17:16 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 19 Feb 2024 14:45:18 +0000 (22:45 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/macOS/fileproviderxpc_mac.mm

index 22cd6ab60acbbe16f434d4970bc9c9d32ff2bab4..260804b71bc31bb0a41402466c6c3e866a59f74c 100644 (file)
@@ -104,9 +104,37 @@ void FileProviderXPC::slotAccountStateChanged(const AccountState::State state) c
 }
 void FileProviderXPC::createDebugArchiveForExtension(const QString &extensionAccountId, const QString &filename) const
 {
+    qCInfo(lcFileProviderXPC) << "Creating debug archive for extension" << extensionAccountId << "at" << filename;
+    // You need to fetch the contents from the extension and then create the archive from the client side.
+    // The extension is not allowed to ask for permission to write into the file system as it is not a user facing process.
     const auto clientCommService = (NSObject<ClientCommunicationProtocol> *)_clientCommServices.value(extensionAccountId);
-    NSURL *const fileURL = [NSURL fileURLWithPath:filename.toNSString()];
-    [clientCommService createDebugArchiveAtURL:fileURL];
+    const auto group = dispatch_group_create();
+    __block NSString *rcvdDebugLogString;
+    dispatch_group_enter(group);
+    [clientCommService createDebugLogStringWithCompletionHandler:^(NSString *const debugLogString, NSError *const error) {
+        if (error != nil) {
+            qCWarning(lcFileProviderXPC) << "Error getting debug log string" << error.localizedDescription;
+            dispatch_group_leave(group);
+            return;
+        } else if (debugLogString == nil) {
+            qCWarning(lcFileProviderXPC) << "Debug log string is nil";
+            dispatch_group_leave(group);
+            return;
+        }
+        rcvdDebugLogString = [NSString stringWithString:debugLogString];
+        [rcvdDebugLogString retain];
+        dispatch_group_leave(group);
+    }];
+    dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
+
+    QFile debugLogFile(filename);
+    if (debugLogFile.open(QIODevice::WriteOnly)) {
+        debugLogFile.write(rcvdDebugLogString.UTF8String);
+        debugLogFile.close();
+        qCInfo(lcFileProviderXPC) << "Debug log file written to" << filename;
+    } else {
+        qCWarning(lcFileProviderXPC) << "Could not open debug log file" << filename;
+    }
 }
 
 } // namespace OCC::Mac