Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fs/ftpfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,8 @@ def openbin(self, path, mode="r", buffering=-1, **options):
else:
if info.is_dir:
raise errors.FileExpected(path)
if _mode.exclusive:
raise errors.FileExists(path)
if _mode.exclusive:
raise errors.FileExists(path)
ftp_file = FTPFile(self, _path, mode)
return ftp_file # type: ignore

Expand Down
6 changes: 3 additions & 3 deletions fs/osfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ def openbin(self, path, mode="r", buffering=-1, **options):
_path = self.validatepath(path)
sys_path = self._to_sys_path(_path)
with convert_os_errors("openbin", path):
if six.PY2 and _mode.exclusive and self.exists(path):
raise errors.FileExists(path)
if six.PY2 and _mode.exclusive:
sys_path = os.open(sys_path, os.O_RDWR | os.O_CREAT | os.O_EXCL)
binary_file = io.open(
sys_path, mode=_mode.to_platform_bin(), buffering=buffering, **options
)
Expand Down Expand Up @@ -416,7 +416,7 @@ def open(
sys_path = self._to_sys_path(_path)
with convert_os_errors("open", path):
if six.PY2 and _mode.exclusive:
sys_path = os.open(sys_path, os.O_CREAT | os.O_EXCL)
sys_path = os.open(sys_path, os.O_RDWR | os.O_CREAT | os.O_EXCL)
_encoding = encoding or "utf-8"
return io.open(
sys_path,
Expand Down
18 changes: 14 additions & 4 deletions fs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,6 @@ def test_open(self):
f.write(text)
self.assertTrue(f.closed)

with self.assertRaises(errors.FileExists):
with self.fs.open("foo/hello", "xt") as f:
pass

# Read it back
with self.fs.open("foo/hello", "rt") as f:
self.assertIsInstance(f, io.IOBase)
Expand Down Expand Up @@ -971,6 +967,20 @@ def test_openbin(self):
with self.assertRaises(ValueError):
self.fs.openbin("foo.bin", "h")

def test_open_exclusive(self):
with self.fs.open("test_open_exclusive", "x") as f:
f.write("bananas")

with self.assertRaises(errors.FileExists):
self.fs.open("test_open_exclusive", "x")

def test_openbin_exclusive(self):
with self.fs.openbin("test_openbin_exclusive", "x") as f:
f.write(b"bananas")

with self.assertRaises(errors.FileExists):
self.fs.openbin("test_openbin_exclusive", "x")

def test_opendir(self):
# Make a simple directory structure
self.fs.makedir("foo")
Expand Down