Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ extension Enumerator {
guard receivedFile.directory ||
serverUrl == dbManager.account.davFilesUrl ||
receivedFile.fullUrlMatches(dbManager.account.davFilesUrl + "/.") ||
(receivedFile.fileName == "." && receivedFile.serverUrl == "..")
(receivedFile.fileName == NextcloudKit.shared.nkCommonInstance.rootFileName && receivedFile.serverUrl == dbManager.account.davFilesUrl)
else {
logger.debug("Read item is a file, converting.", [.url: serverUrl])
var metadata = receivedFile.toItemMetadata()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ extension NKFile {

// Don't ask me why, NextcloudKit renames and moves the root folder details
// Also don't ask me why, but, NextcloudKit marks the NKFile for this as not a directory
let rootRequiresFixup = serverUrl == ".." && fileName == "."
let rootServerUrl = urlBase + Account.webDavFilesUrlSuffix + userId
let rootRequiresFixup = serverUrl == rootServerUrl && fileName == NextcloudKit.shared.nkCommonInstance.rootFileName
let ocId = rootRequiresFixup
? NSFileProviderItemIdentifier.rootContainer.rawValue
: self.ocId
let directory = rootRequiresFixup ? true : self.directory
let serverUrl = rootRequiresFixup
? urlBase + Account.webDavFilesUrlSuffix + userId
: self.serverUrl
let serverUrl = rootRequiresFixup ? rootServerUrl : self.serverUrl
let fileName = rootRequiresFixup ? "" : self.fileName

return SendableItemMetadata(
Expand Down
4 changes: 2 additions & 2 deletions Tests/Interface/MockRemoteItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public class MockRemoteItem: Equatable {
let isRoot = identifier == NSFileProviderItemIdentifier.rootContainer.rawValue
var file = NKFile()
file.fileName = isRoot
? "."
? "__NC_ROOT__"
: trashbinOriginalLocation?.split(separator: "/").last?.toString() ?? name
file.size = size
file.date = creationDate
Expand All @@ -149,7 +149,7 @@ public class MockRemoteItem: Equatable {
file.ocId = identifier
file.fileId = identifier.replacingOccurrences(of: trashedItemIdSuffix, with: "")
file.serverUrl = isRoot
? ".."
? serverUrl + "/remote.php/dav/files/" + userId
: parent?.remotePath ?? remotePath
file.account = account
file.user = username
Expand Down
4 changes: 2 additions & 2 deletions Tests/InterfaceTests/MockRemoteInterfaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,9 @@ final class MockRemoteInterfaceTests: XCTestCase {
let targetRootFile = result.files.first
let expectedRoot = remoteInterface.rootItem
XCTAssertEqual(targetRootFile?.ocId, expectedRoot?.identifier)
XCTAssertEqual(targetRootFile?.fileName, ".") // NextcloudKit gives the root dir this name
XCTAssertEqual(targetRootFile?.fileName, "__NC_ROOT__") // NextcloudKit gives the root dir this name
XCTAssertNotEqual(targetRootFile?.fileName, expectedRoot?.name)
XCTAssertEqual(targetRootFile?.serverUrl, "..") // NextcloudKit gives the root dir this surl
XCTAssertEqual(targetRootFile?.serverUrl, "https://mock.nc.com/remote.php/dav/files/testUserId") // NextcloudKit gives the root dir this url
XCTAssertEqual(targetRootFile?.date, expectedRoot?.creationDate)
XCTAssertEqual(targetRootFile?.etag, expectedRoot?.versionIdentifier)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ final class NKFileExtensionsTests: NextcloudFileProviderKitTestCase {
// which has a special serverUrl and fileName.
let rootNKFile = createNKFile(
ocId: "rootId",
serverUrl: "..", // Special root value
fileName: ".", // Special root value
serverUrl: "https://mock.nc.com/remote.php/dav/files/testUserId", // Special root value
fileName: "__NC_ROOT__", // Special root value
directory: false // NextcloudKit sometimes marks the root as not a directory
)

Expand Down Expand Up @@ -99,8 +99,8 @@ final class NKFileExtensionsTests: NextcloudFileProviderKitTestCase {
// 1. Arrange: Create an array of NKFiles where the first item is the special root.
let rootNKFile = createNKFile(
ocId: "rootId", // This will be overridden by the logic
serverUrl: "..",
fileName: ".",
serverUrl: "https://mock.nc.com/remote.php/dav/files/testUserId",
fileName: "__NC_ROOT__",
directory: false // Mimic NextcloudKit behavior
)
let childNKFile = createNKFile(
Expand Down