Skip to content

fix: keep manual photo uploads in the selected folder - #4492

Open
mvanhorn wants to merge 3 commits into
nextcloud:masterfrom
mvanhorn:fix/4102-manual-upload-destination
Open

mvanhorn wants to merge 3 commits into
nextcloud:masterfrom
mvanhorn:fix/4102-manual-upload-destination

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Nov 25, 2026 •

Copy link
Copy Markdown

A manual photo or video upload could land in a dated Auto Upload subfolder even after the user turned off the Auto Upload destination and selected another folder. The save code chose the correct base folder, then replaced it with a dated Auto Upload path whenever the saved subfolder preference was enabled. That check ignored whether Auto Upload was the selected destination.

Each asset now gets a dated path only when both the Auto Upload destination and its subfolders are enabled. Items backed by temporary files now pass the base folder straight to their metadata; they never shared the PHAsset loop's path, so that part makes the destination explicit rather than fixing a second bug. Tests cover all three flag combinations of manualUploadServerUrl.

swift_tests ran no tests because no Swift package owns the changed files.
repo_lint ran twice with no recorded output or exit status.
A run with the ios NCUploadAssetsModel: change reverted gave no clear result, so no test is shown to catch this bug.
The tests in Tests/NextcloudUnitTests/NCUploadAssetsModelTests.swift did not run here: no test runner for it was available. Both changed files pass swiftc -parse.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

AI was used for assistance.

Fixes #4102

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 nextcloud#4102

Assisted-by: AI
Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the upload-destination fix, though the new regression test was not run in the reported environment.

No open issues 🎉

What changed in this PR

Fixes #4102 by keeping manual photo and video uploads in the selected folder when Auto Upload is disabled, even if its dated-subfolder preference remains enabled.

Changes:

  • Uses dated paths only when both the Auto Upload destination and subfolders are enabled.
  • Keeps temporary-file uploads in the base folder rather than inheriting a previous asset’s destination.
  • Adds a regression test and registers it with the unit-test target.

The new test was not run in the reported environment.

File Description
Tests/​NextcloudUnitTests/​NCUploadAssetsModelTests.swift Tests that a saved subfolder preference does not override the selected folder.
Nextcloud.xcodeproj/​project.pbxproj Adds the regression test to the unit-test target.
iOSClient/​Main/​Create/​Upload Assets/​NCUploadAssetsModel.swift Corrects destination selection for assets and temporary files.

Review effort: Balanced

@marinofaggiana marinofaggiana left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for tracking this down, @mvanhorn! The diagnosis is spot on: the "create subfolders" toggle is only visible when "use Auto Upload folder" is on, but its persisted value is still applied in save(), so a hidden true overrides the folder the user picked. Requiring both flags matches how the view and createMetadatasFolder already behave. 👍

A few small things before we merge:

1. Temp-file loop: the helper call is a no-op
With useAutoUploadSubFolder: false and granularityPath: baseServerUrl, manualUploadServerUrl always returns baseServerUrl. Could you just use it directly?

let metadata = await NCManageDatabaseCreateMetadata().createMetadataAsync(
    fileName: fileName,
    ocId: ocId,
    serverUrl: baseServerUrl,
    ...

Also, assets and tempAssets come from two separate initializers and are never mixed, so on master the temp loop never actually picked up a previous asset's dated path. Making it explicit with baseServerUrl is still a nice improvement, but the PR description and commit message overstate that part a bit.

2. Please extend the test
Right now only one branch of the condition is covered. Please also add:

  • both flags on → returns the granularity path
  • Auto Upload folder on, subfolders off → returns the base URL

Using a consistent value shape for baseServerUrl and granularityPath (both full URLs or both paths) would make the test easier to read. The @MainActor on the suite isn't needed for a pure static function.

3. (Optional) Simpler shape
The static helper with @autoclosure exists mainly to make this testable, which is fine. If you'd rather keep it inline, a plain if useAutoUploadFolder && useAutoUploadSubFolder { … } else { baseServerUrl } would read just as well. Up to you.

4. AI disclosure
The description says AI was used, but the AI checkbox is unticked and marked "N/A". Please tick it. Per the org-wide policy, the trailer should also name the tool and model, e.g. Assisted-by: AGENT_NAME:MODEL_VERSION, instead of just Assisted-by: AI.

Thanks again!

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>
@mvanhorn

Copy link
Copy Markdown
Author

Thanks @marinofaggiana. In 70cd1bf the temp-file loop passes baseServerUrl directly, the tests cover all three flag combinations with full URLs for both values, and the suite no longer has @MainActor; I kept the static helper. The AI box is ticked, the description no longer claims the temp loop fixed a second bug, and the new commit carries an Assisted-by trailer naming the tool and model.

Resolve the project.pbxproj conflict by keeping both the
NCUploadAssetsModelTests entries and the new test and source files
from master.

Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
@mvanhorn

Copy link
Copy Markdown
Author

Merged master into the branch in da60832; the only conflict was Nextcloud.xcodeproj/project.pbxproj, resolved by keeping both sides, and plutil -lint Nextcloud.xcodeproj/project.pbxproj exits 0. git diff --quiet 70cd1bf8ae64416e3ef8e6b07742411431a4db1b HEAD -- "iOSClient/Main/Create/Upload Assets/NCUploadAssetsModel.swift" Tests/NextcloudUnitTests/NCUploadAssetsModelTests.swift also exits 0, so the fix and tests are unchanged from the last round. One note on point 4: the first commit's trailer still reads Assisted-by: AI, so if you squash on merge, the Assisted-by: Claude Code:claude-opus-5-5 line from the second commit covers the whole change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upload Picture or Videos - wrong folder in Nextcloud

3 participants