python-atomicwrites icon indicating copy to clipboard operation
python-atomicwrites copied to clipboard

Use Linux' O_TMPFILE for tmpfiles

Open untitaker opened this issue 10 years ago • 6 comments

https://github.com/untitaker/rust-atomicwrites/issues/2

untitaker avatar Jan 28 '15 20:01 untitaker

Unsure how to call linkat in Python.

untitaker avatar Feb 06 '15 16:02 untitaker

https://docs.python.org/3/library/os.html#os.O_TMPFILE

AndCycle avatar Apr 28 '16 11:04 AndCycle

Something like this seems to work since Python 3.4:

import os
fd = os.open('.', os.O_TMPFILE | os.O_RDWR)
path = '/proc/self/fd/{0}'.format(fd)
os.link(path, 'spam', src_dir_fd=0, follow_symlinks=True)

jwilk avatar Jul 15 '16 11:07 jwilk

@jwilk That doesn't seem particularly performant or elegant though. It seems that there is a package on PyPI that provides bindings for this call, however, that would be quite a microdependency.

untitaker avatar Jul 28 '16 20:07 untitaker

AFAICT NamedTemporaryFile already sets this flag

earonesty avatar Dec 06 '17 21:12 earonesty

I think you meant (unnamed) TemporaryFile, which indeed tries to use O_TMPFILE since Python 3.5: https://bugs.python.org/issue21515

jwilk avatar Dec 06 '17 22:12 jwilk