File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,7 +19,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1919 ([ #527 ] ( https://github.com/PyFilesystem/pyfilesystem2/pull/527 ) ).
2020- Optimized moving files between filesystems with syspaths.
2121 ([ #523 ] ( https://github.com/PyFilesystem/pyfilesystem2/pull/523 ) ).
22- - Fixed ` move.move_file ` to clean up the copy on the destination in case of errors.
22+ - Fixed ` fs.move.move_file ` to clean up the copy on the destination in case of errors.
23+ - ` fs.opener.manage_fs ` with ` writeable=True ` will now raise a ` ResourceReadOnly `
24+ exception if the managed filesystem is not writeable.
2325
2426
2527## [ 2.4.15] - 2022-02-07
Original file line number Diff line number Diff line change @@ -71,13 +71,6 @@ def move_file(
7171 if _src_fs .hassyspath (src_path ) and _dst_fs .hassyspath (dst_path ):
7272 # if both filesystems have a syspath we create a new OSFS from a
7373 # common parent folder and use it to move the file.
74-
75- # we have to raise ResourceReadOnly manually if a FS is read-only
76- if _src_fs .getmeta ().get ("read_only" , True ):
77- raise ResourceReadOnly (_src_fs , src_path )
78- if _dst_fs .getmeta ().get ("read_only" , True ):
79- raise ResourceReadOnly (_dst_fs , dst_path )
80-
8174 try :
8275 src_syspath = _src_fs .getsyspath (src_path )
8376 dst_syspath = _dst_fs .getsyspath (dst_path )
@@ -136,10 +129,10 @@ def move_dir(
136129 """
137130
138131 def src ():
139- return manage_fs (src_fs , writeable = False )
132+ return manage_fs (src_fs , writeable = True )
140133
141134 def dst ():
142- return manage_fs (dst_fs , create = True )
135+ return manage_fs (dst_fs , writeable = True , create = True )
143136
144137 with src () as _src_fs , dst () as _dst_fs :
145138 with _src_fs .lock (), _dst_fs .lock ():
Original file line number Diff line number Diff line change 1414
1515from .base import Opener
1616from .errors import UnsupportedProtocol , EntryPointError
17+ from ..errors import ResourceReadOnly
1718from .parse import parse_fs_url
1819
1920if typing .TYPE_CHECKING :
@@ -282,10 +283,18 @@ def manage_fs(
282283 """
283284 from ..base import FS
284285
286+ def assert_writeable (fs ):
287+ if fs .getmeta ().get ("read_only" , True ):
288+ raise ResourceReadOnly (path = str (fs_url ))
289+
285290 if isinstance (fs_url , FS ):
291+ if writeable :
292+ assert_writeable (fs_url )
286293 yield fs_url
287294 else :
288295 _fs = self .open_fs (fs_url , create = create , writeable = writeable , cwd = cwd )
296+ if writeable :
297+ assert_writeable (_fs )
289298 try :
290299 yield _fs
291300 finally :
You can’t perform that action at this time.
0 commit comments