Skip to content

[19.0][FIX] fs_attachment: don't move a file shared with other attachments - #678

Open
abdulrahman-d1 wants to merge 1 commit into
OCA:19.0from
abdulrahman-d1:19.0-fix-fs_attachment-shared-file-rename
Open

abdulrahman-d1 wants to merge 1 commit into
OCA:19.0from
abdulrahman-d1:19.0-fix-fs_attachment-shared-file-rename

Conversation

@abdulrahman-d1

@abdulrahman-d1 abdulrahman-d1 commented Oct 5, 2026 •

Copy link
Copy Markdown

Uploading a duplicate file can break an older attachment with the same content. The older attachment stays listed, but its file is gone and it opens empty.

It happens when filename obfuscation was on and is now off:

  1. While obfuscation is on, the module stores each file under the checksum of its content, so attachments with the same content share one file.
  2. Once it is off, the module still stores a new file under its checksum, then renames it to <name>-<id>-<version>.<ext>.
  3. If an older attachment uses that checksum file, the rename takes it away.

We hit this after an upgrade. Our older attachments were stored under their checksum, and the new setup has obfuscation off.

Example

Step Attachment 1 Attachment 2
Obfuscation on, upload report.pdf 2aae6c35...
Obfuscation off, upload report.pdf again 2aae6c35..., which no longer exists report-2-0.pdf
Same step with this fix 2aae6c35... report-2-0.pdf, a copy

Fix

The module now copies the file when other attachments still use it, and renames it only when none does. Changing an attachment's name follows the same rule. This also covers duplicates created in one call, so I removed the special case that came with #646.

How to test

  1. On a storage used as default for attachments, tick "Use Filename Obfuscation" and upload a file.
  2. Untick it and upload the same file again.
  3. Open the first attachment. Before the fix it is empty.

Assisted By: Claude Fable 5.1

@oca-cla-bot

oca-cla-bot Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @lmignon,
some modules you are maintaining are being modified, check this out!

With filename obfuscation off, storing or renaming an attachment renames
its file. Attachments stored while obfuscation was on share one file per
content, so that rename moved the file away from the others and they
lost their content.

Copy the file when other attachments still use it, and move it only when
none does. One grouped query per call counts the attachments on each
file. It also covers duplicates created in one call, so the special case
for them is gone.
@abdulrahman-d1
abdulrahman-d1 force-pushed the 19.0-fix-fs_attachment-shared-file-rename branch from 9935cee to 9d365a3 Compare October 5, 2026 16:42
@abdulrahman-d1
abdulrahman-d1 marked this pull request as ready for review October 5, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants