mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-20 13:17:27 +00:00
Merge pull request #1317 from enkore/issue/1315
test_atime: try to open with O_NOATIME to determine support
This commit is contained in:
commit
841d0fd3ad
1 changed files with 14 additions and 2 deletions
|
@ -17,7 +17,7 @@
|
|||
import pytest
|
||||
|
||||
from .. import xattr
|
||||
from ..archive import Archive, ChunkBuffer, CHUNK_MAX_EXP
|
||||
from ..archive import Archive, ChunkBuffer, CHUNK_MAX_EXP, flags_noatime, flags_normal
|
||||
from ..archiver import Archiver
|
||||
from ..cache import Cache
|
||||
from ..crypto import bytes_to_long, num_aes_blocks
|
||||
|
@ -363,8 +363,20 @@ def filter(output):
|
|||
self.assert_equal(filter(info_output), filter(info_output2))
|
||||
|
||||
def test_atime(self):
|
||||
def has_noatime(some_file):
|
||||
atime_before = os.stat(some_file).st_atime_ns
|
||||
try:
|
||||
os.close(os.open(some_file, flags_noatime))
|
||||
except PermissionError:
|
||||
return False
|
||||
else:
|
||||
atime_after = os.stat(some_file).st_atime_ns
|
||||
noatime_used = flags_noatime != flags_normal
|
||||
return noatime_used and atime_before == atime_after
|
||||
|
||||
self.create_test_files()
|
||||
atime, mtime = 123456780, 234567890
|
||||
have_noatime = has_noatime('input/file1')
|
||||
os.utime('input/file1', (atime, mtime))
|
||||
self.cmd('init', self.repository_location)
|
||||
self.cmd('create', self.repository_location + '::test', 'input')
|
||||
|
@ -373,7 +385,7 @@ def test_atime(self):
|
|||
sti = os.stat('input/file1')
|
||||
sto = os.stat('output/input/file1')
|
||||
assert sti.st_mtime_ns == sto.st_mtime_ns == mtime * 1e9
|
||||
if hasattr(os, 'O_NOATIME'):
|
||||
if have_noatime:
|
||||
assert sti.st_atime_ns == sto.st_atime_ns == atime * 1e9
|
||||
else:
|
||||
# it touched the input file's atime while backing it up
|
||||
|
|
Loading…
Reference in a new issue