MCPcopy
hub / github.com/borgbackup/borg / test_atime

Function test_atime

src/borg/testsuite/archiver/extract_cmd_test.py:130–162  ·  view source on GitHub ↗
(archivers, request)

Source from the content-addressed store, hash-verified

128
129@pytest.mark.skipif(not is_utime_fully_supported(), reason="cannot properly setup and execute test without utime")
130def test_atime(archivers, request):
131 archiver = request.getfixturevalue(archivers)
132
133 def has_noatime(some_file):
134 atime_before = os.stat(some_file).st_atime_ns
135 try:
136 with open(os.open(some_file, flags_noatime)) as file:
137 file.read()
138 except PermissionError:
139 return False
140 else:
141 atime_after = os.stat(some_file).st_atime_ns
142 noatime_used = flags_noatime != flags_normal
143 return noatime_used and atime_before == atime_after
144
145 create_test_files(archiver.input_path)
146 atime, mtime = 123456780, 234567890
147 have_noatime = has_noatime("input/file1")
148 os.utime("input/file1", (atime, mtime))
149 cmd(archiver, "repo-create", RK_ENCRYPTION)
150 cmd(archiver, "create", "--atime", "test", "input")
151 with changedir("output"):
152 cmd(archiver, "extract", "test")
153 sti = os.stat("input/file1")
154 sto = os.stat("output/input/file1")
155 assert same_ts_ns(sti.st_mtime_ns, sto.st_mtime_ns)
156 assert same_ts_ns(sto.st_mtime_ns, mtime * 10**9)
157 if have_noatime:
158 assert same_ts_ns(sti.st_atime_ns, sto.st_atime_ns)
159 assert same_ts_ns(sto.st_atime_ns, atime * 10**9)
160 else:
161 # it touched the input file's atime while backing it up
162 assert same_ts_ns(sto.st_atime_ns, atime * 10**9)
163
164
165@pytest.mark.skipif(not is_utime_fully_supported(), reason="cannot setup and execute test without utime")

Callers

nothing calls this directly

Calls 5

create_test_filesFunction · 0.85
cmdFunction · 0.85
changedirFunction · 0.85
same_ts_nsFunction · 0.85
has_noatimeFunction · 0.70

Tested by

no test coverage detected