fix: kopieer met shutil.copyfile (data-only) i.p.v. copy/copy2

copy doet na copyfile ook copymode (os.chmod); op exfat met mountuid=1000
zijn alle bestanden eigendom van uid 1000 en wordt chmod/utime voor de
niet-eigenaar service-gebruiker geweigerd (EPERM op elke kopie, ook na de
copy2-fix). copyfile schrijft alleen data; verificatie gebeurt op grootte
en mode/opnametijd voegen op exfat niets toe.
This commit is contained in:
Eddy de Vink 2026-10-15 20:17:09 +02:00
commit 69d08ba8ba
3 changed files with 19 additions and 16 deletions

View file

@ -85,7 +85,7 @@ class CopyFileTest(unittest.TestCase):
self.assertEqual(os.path.getsize(self.dst), 100)
def test_retries_then_succeeds(self):
real_copy = dashcam.shutil.copy
real_copy = dashcam.shutil.copyfile
calls = {"n": 0}
def flaky(s, d):
@ -94,13 +94,13 @@ class CopyFileTest(unittest.TestCase):
raise OSError(errno.EIO, "I/O error")
real_copy(s, d)
with mock.patch.object(dashcam.shutil, "copy", side_effect=flaky):
with mock.patch.object(dashcam.shutil, "copyfile", side_effect=flaky):
dashcam.copy_file(self.src, self.dst, attempts=3, delay=0)
self.assertEqual(calls["n"], 3)
self.assertEqual(os.path.getsize(self.dst), 100)
def test_raises_after_exhausting_attempts(self):
with mock.patch.object(dashcam.shutil, "copy", side_effect=OSError(errno.EIO, "I/O error")):
with mock.patch.object(dashcam.shutil, "copyfile", side_effect=OSError(errno.EIO, "I/O error")):
with self.assertRaises(OSError):
dashcam.copy_file(self.src, self.dst, attempts=2, delay=0)
@ -159,7 +159,7 @@ class TransferFilesTest(unittest.TestCase):
with open(d, "wb") as f:
f.write(b"0" * 50)
with mock.patch.object(dashcam.shutil, "copy", side_effect=bad_copy), mock.patch.object(
with mock.patch.object(dashcam.shutil, "copyfile", side_effect=bad_copy), mock.patch.object(
dashcam.time, "sleep"
):
ok, errors = dashcam.transfer_files(files, self.src, self.base)
@ -172,7 +172,7 @@ class TransferFilesTest(unittest.TestCase):
for i in range(dashcam.MAX_CONSECUTIVE_ERRORS + 3)
]
with mock.patch.object(
dashcam.shutil, "copy", side_effect=OSError(errno.EIO, "I/O error")
dashcam.shutil, "copyfile", side_effect=OSError(errno.EIO, "I/O error")
), mock.patch.object(dashcam.time, "sleep"):
with self.assertRaises(dashcam.TransferAborted) as ctx:
dashcam.transfer_files(files, self.src, self.base)