Improve check for O_TMPFILE support in unit tests

On Python < 3.4, there is no os.O_TMPFILE, so the check for O_TMPFILE
support was always reporting no-support. We now use utils.O_TMPFILE,
which is always defined.

Also, when opening an anonymous tempfile, you must open the directory
(not a file in the directory) with three flags or-ed together:
O_DIRECTORY, O_WRONLY, and O_TMPFILE. Calling open() with a subset of
those flags will receive either EISDIR or EINVAL. The check was trying
to open a file in the temp dir, so was always reporting no-support for
O_TMPFILE. We now correctly open the tempdir.

Change-Id: Iaf48ad9aecea73df4e794818dd15070360bff19f
This commit is contained in:
Samuel Merritt 2018-04-10 16:33:09 -07:00
parent bbf5e5c7f3
commit b0b3ed0309

View File

@ -4396,37 +4396,21 @@ def modify_priority(conf, logger):
def o_tmpfile_in_path_supported(dirpath):
if not hasattr(os, 'O_TMPFILE'):
return False
testfile = os.path.join(dirpath, ".o_tmpfile.test")
hasO_TMPFILE = True
fd = None
try:
fd = os.open(testfile, os.O_CREAT | os.O_WRONLY | os.O_TMPFILE)
fd = os.open(dirpath, os.O_WRONLY | O_TMPFILE)
return True
except OSError as e:
if e.errno == errno.EINVAL:
hasO_TMPFILE = False
if e.errno in (errno.EINVAL, errno.EISDIR, errno.EOPNOTSUPP):
return False
else:
raise Exception("Error on '%(path)s' while checking "
"O_TMPFILE: '%(ex)s'",
{'path': dirpath, 'ex': e})
except Exception as e:
raise Exception("Error on '%(path)s' while checking O_TMPFILE: "
"'%(ex)s'", {'path': dirpath, 'ex': e})
finally:
if fd is not None:
os.close(fd)
# ensure closing the fd will actually remove the file
if os.path.isfile(testfile):
return False
return hasO_TMPFILE
def o_tmpfile_in_tmpdir_supported():
return o_tmpfile_in_path_supported(gettempdir())