4 ms·
On Linux, you can use O_TMPFILE to ensure that the temporary file won't linger around if an error occurs: foo: bar generate bar | python3 -c "impor
by 10000truths 3y ago
On Linux, you can use O_TMPFILE to ensure that the temporary file won't linger around if an error occurs:
foo: bar
generate bar | python3 -c "import os,sys;f=os.open('.',os.O_RDWR|os.O_TMPFILE);os.write(f,sys.stdin.buffer.read());os.link(f'/proc/self/fd/{f}','./foo')"
- admax88qqq 3y agoLol. Files were a mistake.
- throwaway67743 3y agoThis is everything that's wrong with modern software. Do not introduce a pointless dependency like python because of a lack of knowledge about the build system of choice. Just use something more appropriate (that isn't python).
- 10000truths 3y agoYou're missing the point. The important part isn't the Python, it's the opening of a file with O_TMPFILE, writing to it, and linking it into the filesystem in order to guarantee an atomic result without risking leaking temporary files. If your requirements forbid the use of Python for whatever reason, you are welcome to substitute it with any other program that can perform the aforementioned operations.
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]