Skip to content

Commit 3d801a0

Browse files
sqwishywillmcgugan
authored andcommitted
Use os.open() in osfs in exclusive mode (#182) (#189)
`io.open()` takes a file descriptor, `os.open()` returns one and lets you pass O_EXCL to open the file.
1 parent ed8af08 commit 3d801a0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/osfs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,8 @@ def open(self,
422422
_path = self.validatepath(path)
423423
sys_path = self._to_sys_path(_path)
424424
with convert_os_errors('open', path):
425-
if six.PY2 and _mode.exclusive and self.exists(path):
426-
raise FileExists(path)
425+
if six.PY2 and _mode.exclusive:
426+
sys_path = os.open(sys_path, os.O_CREAT | os.O_EXCL)
427427
_encoding = encoding or 'utf-8'
428428
return io.open(
429429
sys_path,

0 commit comments

Comments
 (0)