Skip to content

Commit 480bdca

Browse files
[IMP] fs_storage: add _move_file method
1 parent f9b6dbc commit 480bdca

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

fs_storage/models/fs_storage.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import os.path
1111
import re
1212
import warnings
13+
from pathlib import PurePath
1314
from typing import AnyStr
1415

1516
import fsspec
@@ -819,3 +820,19 @@ def _get_root_filesystem(self, fs=None):
819820
while hasattr(fs, "fs"):
820821
fs = fs.fs
821822
return fs
823+
824+
def _move_file(self, from_dir_str, to_dir_str, filename):
825+
self.ensure_one()
826+
from_dir = PurePath(from_dir_str)
827+
to_dir = PurePath(to_dir_str)
828+
if not self.fs.exists(from_dir.as_posix()):
829+
return False
830+
files = [
831+
os.path.basename(f) for f in self.fs.ls(from_dir.as_posix(), detail=False)
832+
]
833+
if filename not in files:
834+
return False
835+
src = (from_dir / filename).as_posix()
836+
dst = (to_dir / filename).as_posix()
837+
self.env.cr.postcommit.add(functools.partial(self.fs.move, src, dst))
838+
return True

0 commit comments

Comments
 (0)