@@ -671,7 +671,7 @@ def lstat(self, path: AnyStr, *, dir_fd: Optional[int] = None) -> FakeStatResult
671
671
OSError: if the filesystem object doesn't exist.
672
672
"""
673
673
# stat should return the tuple representing return value of os.stat
674
- path = self ._path_with_dir_fd (path , self .lstat , dir_fd )
674
+ path = self ._path_with_dir_fd (path , self .lstat , dir_fd , check_supported = False )
675
675
return self .filesystem .stat (path , follow_symlinks = False )
676
676
677
677
def remove (self , path : AnyStr , dir_fd : Optional [int ] = None ) -> None :
@@ -687,7 +687,7 @@ def remove(self, path: AnyStr, dir_fd: Optional[int] = None) -> None:
687
687
OSError: if path does not exist.
688
688
OSError: if removal failed.
689
689
"""
690
- path = self ._path_with_dir_fd (path , self .remove , dir_fd )
690
+ path = self ._path_with_dir_fd (path , self .remove , dir_fd , check_supported = False )
691
691
self .filesystem .remove (path )
692
692
693
693
def unlink (self , path : AnyStr , * , dir_fd : Optional [int ] = None ) -> None :
@@ -798,8 +798,12 @@ def replace(
798
798
OSError: if the file would be moved to another filesystem
799
799
(e.g. mount point)
800
800
"""
801
- src = self ._path_with_dir_fd (src , self .rename , src_dir_fd )
802
- dst = self ._path_with_dir_fd (dst , self .rename , dst_dir_fd )
801
+ src = self ._path_with_dir_fd (
802
+ src , self .rename , src_dir_fd , check_supported = False
803
+ )
804
+ dst = self ._path_with_dir_fd (
805
+ dst , self .rename , dst_dir_fd , check_supported = False
806
+ )
803
807
self .filesystem .rename (src , dst , force_replace = True )
804
808
805
809
def rmdir (self , path : AnyStr , * , dir_fd : Optional [int ] = None ) -> None :
@@ -891,7 +895,11 @@ def makedirs(
891
895
self .filesystem .makedirs (name , mode , exist_ok )
892
896
893
897
def _path_with_dir_fd (
894
- self , path : AnyStr , fct : Callable , dir_fd : Optional [int ]
898
+ self ,
899
+ path : AnyStr ,
900
+ fct : Callable ,
901
+ dir_fd : Optional [int ],
902
+ check_supported : bool = True ,
895
903
) -> AnyStr :
896
904
"""Return the path considering dir_fd. Raise on invalid parameters."""
897
905
try :
@@ -901,7 +909,7 @@ def _path_with_dir_fd(
901
909
path = path
902
910
if dir_fd is not None :
903
911
# check if fd is supported for the built-in real function
904
- if fct not in self .supports_dir_fd :
912
+ if check_supported and ( fct not in self .supports_dir_fd ) :
905
913
raise NotImplementedError ("dir_fd unavailable on this platform" )
906
914
if isinstance (path , int ):
907
915
raise ValueError (
@@ -1162,12 +1170,12 @@ def symlink(
1162
1170
dst: Path to the symlink to create.
1163
1171
target_is_directory: Currently ignored.
1164
1172
dir_fd: If not `None`, the file descriptor of a directory,
1165
- with `src ` being relative to this directory.
1173
+ with `dst ` being relative to this directory.
1166
1174
1167
1175
Raises:
1168
1176
OSError: if the file already exists.
1169
1177
"""
1170
- src = self ._path_with_dir_fd (src , self .symlink , dir_fd )
1178
+ dst = self ._path_with_dir_fd (dst , self .symlink , dir_fd )
1171
1179
self .filesystem .create_symlink (dst , src , create_missing_dirs = False )
1172
1180
1173
1181
def link (
@@ -1178,7 +1186,7 @@ def link(
1178
1186
src_dir_fd : Optional [int ] = None ,
1179
1187
dst_dir_fd : Optional [int ] = None ,
1180
1188
) -> None :
1181
- """Create a hard link at new_path , pointing at old_path .
1189
+ """Create a hard link at dst , pointing at src .
1182
1190
1183
1191
Args:
1184
1192
src: An existing path to the target file.
0 commit comments