Skip to content

Commit beade7f

Browse files
authored
Merge pull request #679 from martindurant/mkdir_twice
Do not ignore existing dir in local mkdir
2 parents 0c469bf + 2eb83d0 commit beade7f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

fsspec/implementations/local.py

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def __init__(self, auto_mkdir=False, **kwargs):
3333

3434
def mkdir(self, path, create_parents=True, **kwargs):
3535
path = self._strip_protocol(path)
36+
if self.exists(path):
37+
raise FileExistsError(path)
3638
if create_parents:
3739
self.makedirs(path, exist_ok=True)
3840
else:

fsspec/implementations/tests/test_local.py

+8
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,14 @@ def test_strip_protocol_expanduser():
576576
assert not LocalFileSystem._strip_protocol("./").endswith("/")
577577

578578

579+
def test_mkdir_twice_faile(tmpdir):
580+
fn = os.path.join(tmpdir, "test")
581+
fs = fsspec.filesystem("file")
582+
fs.mkdir(fn)
583+
with pytest.raises(FileExistsError):
584+
fs.mkdir(fn)
585+
586+
579587
def test_iterable(tmpdir):
580588
data = b"a\nhello\noi"
581589
fn = os.path.join(tmpdir, "test")

0 commit comments

Comments
 (0)