mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-23 00:07:38 +00:00
parent
8a409ec1fb
commit
0132eee1d4
1 changed files with 31 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
|||
import errno
|
||||
import hashlib
|
||||
import os
|
||||
import shutil
|
||||
|
@ -30,6 +31,7 @@
|
|||
from ..helpers import dash_open
|
||||
from ..helpers import iter_separated
|
||||
from ..helpers import eval_escapes
|
||||
from ..helpers import safe_unlink
|
||||
|
||||
from . import BaseTestCase, FakeInputs
|
||||
|
||||
|
@ -1133,3 +1135,32 @@ def test_iter_separated():
|
|||
def test_eval_escapes():
|
||||
assert eval_escapes('\\n\\0\\x23') == '\n\0#'
|
||||
assert eval_escapes('äç\\n') == 'äç\n'
|
||||
|
||||
|
||||
def test_safe_unlink_is_safe(tmpdir):
|
||||
contents = b"Hello, world\n"
|
||||
victim = tmpdir / 'victim'
|
||||
victim.write_binary(contents)
|
||||
hard_link = tmpdir / 'hardlink'
|
||||
hard_link.mklinkto(victim)
|
||||
|
||||
safe_unlink(hard_link)
|
||||
|
||||
assert victim.read_binary() == contents
|
||||
|
||||
|
||||
def test_safe_unlink_is_safe_ENOSPC(tmpdir, monkeypatch):
|
||||
contents = b"Hello, world\n"
|
||||
victim = tmpdir / 'victim'
|
||||
victim.write_binary(contents)
|
||||
hard_link = tmpdir / 'hardlink'
|
||||
hard_link.mklinkto(victim)
|
||||
|
||||
def os_unlink(_):
|
||||
raise OSError(errno.ENOSPC, "Pretend that we ran out of space")
|
||||
monkeypatch.setattr(os, "unlink", os_unlink)
|
||||
|
||||
with pytest.raises(OSError):
|
||||
safe_unlink(hard_link)
|
||||
|
||||
assert victim.read_binary() == contents
|
||||
|
|
Loading…
Reference in a new issue