Merge "Improve check for O_TMPFILE support in unit tests"
This commit is contained in:
commit
0a6f0d615c
@ -4396,37 +4396,21 @@ def modify_priority(conf, logger):
|
|||||||
|
|
||||||
|
|
||||||
def o_tmpfile_in_path_supported(dirpath):
|
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
|
fd = None
|
||||||
try:
|
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:
|
except OSError as e:
|
||||||
if e.errno == errno.EINVAL:
|
if e.errno in (errno.EINVAL, errno.EISDIR, errno.EOPNOTSUPP):
|
||||||
hasO_TMPFILE = False
|
return False
|
||||||
else:
|
else:
|
||||||
raise Exception("Error on '%(path)s' while checking "
|
raise Exception("Error on '%(path)s' while checking "
|
||||||
"O_TMPFILE: '%(ex)s'",
|
"O_TMPFILE: '%(ex)s'",
|
||||||
{'path': dirpath, 'ex': e})
|
{'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:
|
finally:
|
||||||
if fd is not None:
|
if fd is not None:
|
||||||
os.close(fd)
|
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():
|
def o_tmpfile_in_tmpdir_supported():
|
||||||
return o_tmpfile_in_path_supported(gettempdir())
|
return o_tmpfile_in_path_supported(gettempdir())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user