osutil: add Libc.futimens() wrapper for futimens() call
Python has no wrapper for a futime*() call so we need to implement it in the `util.linux` package.
This commit is contained in:
parent
ca9f4038c8
commit
f52cabc3c1
2 changed files with 50 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
|||
# Tests for the `osbuild.util.linux` module.
|
||||
#
|
||||
|
||||
import ctypes
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
|
@ -240,3 +241,24 @@ def test_proc_boot_id():
|
|||
|
||||
bootid3 = linux.proc_boot_id("foobar")
|
||||
assert bootid.int != bootid3.int
|
||||
|
||||
|
||||
def test_libc_futimens_errcheck():
|
||||
libc = linux.Libc.default()
|
||||
with pytest.raises(OSError):
|
||||
libc.futimens(-1, None)
|
||||
|
||||
|
||||
def test_libc_futimes_works(tmpdir):
|
||||
libc = linux.Libc.default()
|
||||
stamp_file = os.path.join(tmpdir, "foo")
|
||||
with open(stamp_file, "w") as fp:
|
||||
fp.write("meep")
|
||||
mtime1 = os.stat(stamp_file).st_mtime
|
||||
with open(stamp_file, "w") as fp:
|
||||
libc.futimens(fp.fileno(), ctypes.byref(linux.c_timespec_times2(
|
||||
atime=linux.c_timespec(tv_sec=3, tv_nsec=300*1000*1000),
|
||||
mtime=linux.c_timespec(tv_sec=0, tv_nsec=libc.UTIME_OMIT),
|
||||
)))
|
||||
assert os.stat(stamp_file).st_atime == 3.3
|
||||
assert os.stat(stamp_file).st_mtime == mtime1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue