From b71643a7f0f121b3bc120824cacab45ee90b6c5b Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Wed, 25 Nov 2026 04:43:04 -0800 Subject: [PATCH 1/2] fix: keep manual photo uploads in the selected folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each asset now gets a dated path only when both the Auto Upload destination and its subfolders are enabled. Items backed by temporary files use the base folder, so they cannot inherit the previous asset’s dated path. A regression test covers selecting a folder while the subfolder preference is still enabled. Fixes #4102 Assisted-by: AI Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> --- Nextcloud.xcodeproj/project.pbxproj | 4 +++ .../NCUploadAssetsModelTests.swift | 21 +++++++++++++++ .../Upload Assets/NCUploadAssetsModel.swift | 26 +++++++++++++++---- 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 Tests/NextcloudUnitTests/NCUploadAssetsModelTests.swift diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index ec6b5669ec..e18d90b843 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -150,6 +150,7 @@ C0DEA070306D000100000008 /* NCAutoUploadAssetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0DEA070306D000100000007 /* NCAutoUploadAssetTests.swift */; }; C0DECA022F65000100C0D001 /* NCCameraRollTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0DECA012F65000100C0D001 /* NCCameraRollTests.swift */; }; C0DEDA7E30C1000100A00002 /* NCAutoUploadDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0DEDA7E30C1000100A00001 /* NCAutoUploadDateTests.swift */; }; + BD83FC9730C1000100A00002 /* NCUploadAssetsModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD83FC9730C1000100A00001 /* NCUploadAssetsModelTests.swift */; }; CB3666201AF7550816B5CD6A /* NCContextMenuComment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8932E90EC4278026D86CCCC9 /* NCContextMenuComment.swift */; }; D56DFFE5D5014F66A7C9FED0 /* PasscodeUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC6C501EF1104A6A8569D9C1 /* PasscodeUITests.swift */; }; D5B6AA7827200C7200D49C24 /* NCActivityTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */; }; @@ -1453,6 +1454,7 @@ C0DEA070306D000100000007 /* NCAutoUploadAssetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCAutoUploadAssetTests.swift; sourceTree = ""; }; C0DECA012F65000100C0D001 /* NCCameraRollTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCCameraRollTests.swift; sourceTree = ""; }; C0DEDA7E30C1000100A00001 /* NCAutoUploadDateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCAutoUploadDateTests.swift; sourceTree = ""; }; + BD83FC9730C1000100A00001 /* NCUploadAssetsModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCUploadAssetsModelTests.swift; sourceTree = ""; }; CE0CD9A00D74B01055F238E9 /* NCErrorContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCErrorContext.swift; sourceTree = ""; }; D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityTableViewCell.swift; sourceTree = ""; }; F0A1B2C330B5000100D4E5F6 /* NCMediaViewerFloatingTitleViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCMediaViewerFloatingTitleViewTests.swift; sourceTree = ""; }; @@ -2316,6 +2318,7 @@ children = ( AC13ADAF2026101300000001 /* NCMediaAdaptiveLayoutViewTests.swift */, C0DEDA7E30C1000100A00001 /* NCAutoUploadDateTests.swift */, + BD83FC9730C1000100A00001 /* NCUploadAssetsModelTests.swift */, 320C20803A58DAF7575440A8 /* NKErrorUserFriendlyMessageTests.swift */, C0DEA070306D000100000007 /* NCAutoUploadAssetTests.swift */, F76BED7B306D0000002E1442 /* NCPhotoLibraryAssetTests.swift */, @@ -4712,6 +4715,7 @@ BAF64949B487A080A98F83F2 /* NKErrorUserFriendlyMessageTests.swift in Sources */, AC13ADAF2026101300000002 /* NCMediaAdaptiveLayoutViewTests.swift in Sources */, C0DEDA7E30C1000100A00002 /* NCAutoUploadDateTests.swift in Sources */, + BD83FC9730C1000100A00002 /* NCUploadAssetsModelTests.swift in Sources */, C0DEA070306D000100000008 /* NCAutoUploadAssetTests.swift in Sources */, F76BED7E306D0000002E1442 /* NCPhotoLibraryAssetTests.swift in Sources */, A1E2EE01000000000000000A /* NCEndToEndKeySetArchiveTests.swift in Sources */, diff --git a/Tests/NextcloudUnitTests/NCUploadAssetsModelTests.swift b/Tests/NextcloudUnitTests/NCUploadAssetsModelTests.swift new file mode 100644 index 0000000000..13269eed89 --- /dev/null +++ b/Tests/NextcloudUnitTests/NCUploadAssetsModelTests.swift @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: Nextcloud GmbH +// SPDX-FileCopyrightText: 2026 Matt Van Horn +// SPDX-License-Identifier: GPL-3.0-or-later + +import Testing +@testable import Nextcloud + +@Suite("Manual upload destination") +@MainActor +struct NCUploadAssetsModelTests { + @Test("A saved subfolder preference preserves the selected folder") + func subfolderPreferenceDoesNotOverrideSelectedFolder() { + let destination = NCUploadAssetsModel.manualUploadServerUrl( + baseServerUrl: "/test", + useAutoUploadFolder: false, + useAutoUploadSubFolder: true, + granularityPath: "https://cloud.example/remote.php/dav/files/user/Photos/2026/04" + ) + #expect(destination == "/test") + } +} diff --git a/iOSClient/Main/Create/Upload Assets/NCUploadAssetsModel.swift b/iOSClient/Main/Create/Upload Assets/NCUploadAssetsModel.swift index d10d46c82e..67a73666ae 100644 --- a/iOSClient/Main/Create/Upload Assets/NCUploadAssetsModel.swift +++ b/iOSClient/Main/Create/Upload Assets/NCUploadAssetsModel.swift @@ -248,6 +248,13 @@ class NCUploadAssetsModel: ObservableObject, NCCreateFormUploadConflictDelegate } } + static func manualUploadServerUrl(baseServerUrl: String, + useAutoUploadFolder: Bool, + useAutoUploadSubFolder: Bool, + granularityPath: @autoclosure () -> String) -> String { + useAutoUploadFolder && useAutoUploadSubFolder ? granularityPath() : baseServerUrl + } + func save(completion: @escaping (_ metadatasNOConflict: [tableMetadata], _ metadatasUploadInConflict: [tableMetadata]) -> Void) { Task { @MainActor in @@ -256,8 +263,8 @@ class NCUploadAssetsModel: ObservableObject, NCCreateFormUploadConflictDelegate var metadatasUploadInConflict: [tableMetadata] = [] let autoUploadServerUrlBase = database.getAccountAutoUploadServerUrlBase(session: self.session) - var serverUrl = useAutoUploadFolder ? autoUploadServerUrlBase : self.serverUrl - let isInDirectoryE2EE = NCUtilityFileSystem().isDirectoryE2EE(serverUrl: serverUrl, urlBase: session.urlBase, userId: session.userId, account: session.account) + let baseServerUrl = useAutoUploadFolder ? autoUploadServerUrlBase : self.serverUrl + let isInDirectoryE2EE = NCUtilityFileSystem().isDirectoryE2EE(serverUrl: baseServerUrl, urlBase: session.urlBase, userId: session.userId, account: session.account) for tlAsset in assets { @@ -276,9 +283,12 @@ class NCUploadAssetsModel: ObservableObject, NCCreateFormUploadConflictDelegate && NCPreferences().livePhoto && preview.data == nil - if useAutoUploadSubFolder { - serverUrl = utilityFileSystem.createGranularityPath(asset: asset, serverUrlBase: autoUploadServerUrlBase) - } + let serverUrl = Self.manualUploadServerUrl( + baseServerUrl: baseServerUrl, + useAutoUploadFolder: useAutoUploadFolder, + useAutoUploadSubFolder: useAutoUploadSubFolder, + granularityPath: utilityFileSystem.createGranularityPath(asset: asset, serverUrlBase: autoUploadServerUrlBase) + ) let predicate = NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@ AND session != ''", session.account, serverUrl, fileName) @@ -346,6 +356,12 @@ class NCUploadAssetsModel: ObservableObject, NCCreateFormUploadConflictDelegate for item in previewStore where item.tempURL != nil { guard let url = item.tempURL else { continue } + let serverUrl = Self.manualUploadServerUrl( + baseServerUrl: baseServerUrl, + useAutoUploadFolder: useAutoUploadFolder, + useAutoUploadSubFolder: false, + granularityPath: baseServerUrl + ) let fileName = item.fileName.isEmpty ? url.lastPathComponent From 70cd1bf8ae64416e3ef8e6b07742411431a4db1b Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Thu, 26 Nov 2026 02:35:18 -0800 Subject: [PATCH 2/2] fix: use the base folder for temp files and cover both flags Temp-file items now pass baseServerUrl straight to the metadata, since the helper always returned it there. The tests cover all three flag combinations with one URL shape, and the suite drops @MainActor. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> --- .../NCUploadAssetsModelTests.swift | 32 ++++++++++++++++--- .../Upload Assets/NCUploadAssetsModel.swift | 8 +---- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Tests/NextcloudUnitTests/NCUploadAssetsModelTests.swift b/Tests/NextcloudUnitTests/NCUploadAssetsModelTests.swift index 13269eed89..a9db9c7094 100644 --- a/Tests/NextcloudUnitTests/NCUploadAssetsModelTests.swift +++ b/Tests/NextcloudUnitTests/NCUploadAssetsModelTests.swift @@ -6,16 +6,40 @@ import Testing @testable import Nextcloud @Suite("Manual upload destination") -@MainActor struct NCUploadAssetsModelTests { + let baseServerUrl = "https://cloud.example/remote.php/dav/files/user/Photos" + let granularityPath = "https://cloud.example/remote.php/dav/files/user/Photos/2026/04" + @Test("A saved subfolder preference preserves the selected folder") func subfolderPreferenceDoesNotOverrideSelectedFolder() { let destination = NCUploadAssetsModel.manualUploadServerUrl( - baseServerUrl: "/test", + baseServerUrl: baseServerUrl, useAutoUploadFolder: false, useAutoUploadSubFolder: true, - granularityPath: "https://cloud.example/remote.php/dav/files/user/Photos/2026/04" + granularityPath: granularityPath + ) + #expect(destination == baseServerUrl) + } + + @Test("Auto Upload folder with subfolders uses the dated path") + func autoUploadFolderWithSubfoldersUsesGranularityPath() { + let destination = NCUploadAssetsModel.manualUploadServerUrl( + baseServerUrl: baseServerUrl, + useAutoUploadFolder: true, + useAutoUploadSubFolder: true, + granularityPath: granularityPath + ) + #expect(destination == granularityPath) + } + + @Test("Auto Upload folder without subfolders uses the base folder") + func autoUploadFolderWithoutSubfoldersUsesBaseUrl() { + let destination = NCUploadAssetsModel.manualUploadServerUrl( + baseServerUrl: baseServerUrl, + useAutoUploadFolder: true, + useAutoUploadSubFolder: false, + granularityPath: granularityPath ) - #expect(destination == "/test") + #expect(destination == baseServerUrl) } } diff --git a/iOSClient/Main/Create/Upload Assets/NCUploadAssetsModel.swift b/iOSClient/Main/Create/Upload Assets/NCUploadAssetsModel.swift index 67a73666ae..a89368e887 100644 --- a/iOSClient/Main/Create/Upload Assets/NCUploadAssetsModel.swift +++ b/iOSClient/Main/Create/Upload Assets/NCUploadAssetsModel.swift @@ -356,12 +356,6 @@ class NCUploadAssetsModel: ObservableObject, NCCreateFormUploadConflictDelegate for item in previewStore where item.tempURL != nil { guard let url = item.tempURL else { continue } - let serverUrl = Self.manualUploadServerUrl( - baseServerUrl: baseServerUrl, - useAutoUploadFolder: useAutoUploadFolder, - useAutoUploadSubFolder: false, - granularityPath: baseServerUrl - ) let fileName = item.fileName.isEmpty ? url.lastPathComponent @@ -372,7 +366,7 @@ class NCUploadAssetsModel: ObservableObject, NCCreateFormUploadConflictDelegate let metadata = await NCManageDatabaseCreateMetadata().createMetadataAsync( fileName: fileName, ocId: ocId, - serverUrl: serverUrl, + serverUrl: baseServerUrl, session: session, sceneIdentifier: controller?.sceneIdentifier )