Skip to content

Commit

Permalink
[FIX] Do take nested rooted fs paths into account in computation of s…
Browse files Browse the repository at this point in the history
…tore_fname. Code by @lmignon - Laurent Mignon (ACSONE)
  • Loading branch information
wpichler committed Oct 6, 2023
1 parent 838337a commit 5fea8e7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion fs_attachment/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,20 @@ def _enforce_meaningful_storage_filename(self) -> None:
# we need to update the store_fname with the new filename by
# calling the write method of the field since the write method
# of ir_attachment prevent normal write on store_fname
attachment._force_write_store_fname(f"{storage}://{new_filename_with_path}")

# rooted_dir path computation...
# done by @lmignon - Laurent Mignon (ACSONE)
# there could be a nested rooted dir in the fs path - we do compute it here
# and remove it from the new_filename if it does exists
rooted_paths = []
rooted_dir_fs = fs
while rooted_dir_fs and hasattr(rooted_dir_fs, "path"):
rooted_paths.append(rooted_dir_fs.path)
rooted_dir_fs = getattr(rooted_dir_fs, "fs", None)
rooted_paths.reverse()
rooted_path = "/".join(rooted_paths)
new_filename = new_filename_with_path.replace(rooted_path, "")
attachment._force_write_store_fname(f"{storage}://{new_filename}")
self._fs_mark_for_gc(attachment.store_fname)

def _force_write_store_fname(self, store_fname):
Expand Down

0 comments on commit 5fea8e7

Please sign in to comment.