Skip to content

[BUG] Creating/deleting file via DocumentProvider is not working as expected #4638

Open

Description

@donmor

Actual behaviour

  • Create and save a file via DocumentProvider in another app, and it can't be accessed again, until opened again from SAF.
  • The failed entries has -1 as path while accessible entries has positive integers
  • Deleting a file with persistent uri in another app won't work.

Expected behaviour

  • Create and save a file, and it is created and saved

Steps to reproduce

  1. Setup an owncloud account
  2. Create a file in another app (e.g. Tiddloid) via DocumentProvider
  3. Close the file and try opening it from app's recent file list (for Tiddloid, it is the main activity)

Can this problem be reproduced with the official owncloud server?
(url: https://ocis.ocis.master.owncloud.works, user: einstein, password: relativity)
Unknown. I can't access this server at all.

Environment data

Android version: 13

Device model: Xiaomi 22041216C

Stock or customized system: MIUI14

ownCloud app version: 4.5.1 (43b8579)

ownCloud server version: 7.1.3

Logs

Web server error log

None (my server is currently down)

ownCloud log (data/owncloud.log)

None (my server is currently down)

Activity

  1. jesmrec commented on Jul 14, 2025

    @jesmrec
    Member

    Hi @donmor! i did a check with Tiddloid (installed from F-droid) and could not reproduce the problem. Tiddloid has documents provider access and it is able to save a new wiki file in the chosen folder.

    I recorded a video with the steps i did to create the new file. Let me know if there is something different by comparing to your case, so that we can scope where the problem could be:

    Screen_recording_20250714_091518.mp4
  2. donmor commented on Jul 14, 2025

    @donmor
    Author

    Looks like my description was wrong. Edited.

  3. donmor commented on Jul 14, 2025

    @donmor
    Author

    BTW I can't find ownCloud in SAF "open directory" interface. Will it be an option to enable directory managing / literal path for SAF?

  4. jesmrec commented on Jul 14, 2025

    @jesmrec
    Member

    Now, i was able to reproduce that problem, saved file was not enabled for opening/removing. Will check this.

    BTW I can't find ownCloud in SAF "open directory" interface. Will it be an option to enable directory managing / literal path for SAF?

    that's not implemented ftm. Only available for single files (am i right, @joragua?).

  5. joragua commented on Jul 14, 2025

    @joragua
    Member

    Yes, right! It's only available for single files. Regarding the bug, we will take a look and see what's going on! 🍻

  6. added this to the Backlog milestone on Jul 18, 2025
  7. DeepDiver1975 commented on Jul 2, 2026

    @DeepDiver1975
    Contributor

    Confirmed bug in the app's SAF DocumentsProvider. Located cause: createDocument returns the sentinel document ID "-1" for every newly-created file instead of a real, persistable ID.

    DocumentsStorageProvider.kt (master):

    • createFile() builds fileToUpload but does not persist it, and returns NONEXISTENT_DOCUMENT_ID (= "-1") — L498-518, L615. The real DB id only exists after the async upload+sync completes in openDocument's close listener (L143-154).
    • SAF hands that "-1" back to the calling app as the created document's ID. That's the -1 "path" the reporter sees; genuinely-persisted files get positive ids.

    Consequences when the caller reuses the returned/persisted URI:

    • openDocument("-1", …) → uploadOnly branch (L105) always resolves to the last fileToUpload, not the file the caller meant — so the saved file "can't be accessed again until reopened from SAF".
    • deleteDocument("-1") → getFileByIdOrException((-1).toInt()) → GetFileByIdUseCase(-1) finds nothing → FileNotFoundException (L402-404, L595-599). Delete fails.

    Fix direction: createDocument must return the actual document ID of the created file (SAF requires a stable ID usable for subsequent open/delete/query), not the "-1" sentinel. That likely means the entry must exist in the DB (or the upload be awaited) before returning, so the returned ID resolves in queryDocument/openDocument/deleteDocument.

    Scope note: distinct from the copy/move-between-accounts DocumentProvider bugs reopened 2026-07-01 (#2658/#2659/#2662) — same subsystem, different code path (create/delete of a new file vs. cross-account copy/move).

    🤖 Generated with Claude Code

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions