1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
import unittest
import os
import re
from commontest import old_test_dir, abs_output_dir, MakeOutputDir
from rdiff_backup import Globals, rpath, increment, Time, Rdiff
from rdiffbackup import actions
lc = Globals.local_connection
Globals.change_source_perms = 1
def getrp(ending):
return rpath.RPath(
lc, os.path.join(old_test_dir, b"various_file_types", ending))
base_dir = getrp(b".")
rf = getrp(b"regular_file")
rf2 = getrp(b"two_hardlinked_files1")
exec1 = getrp(b"executable")
sym = getrp(b"symbolic_link")
nothing = getrp(b"nothing")
target = rpath.RPath(lc, os.path.join(abs_output_dir, b"out"))
out2 = rpath.RPath(lc, os.path.join(abs_output_dir, b"out2"))
out_gz = rpath.RPath(lc, os.path.join(abs_output_dir, b"out.gz"))
Time.set_current_time(1000000000)
Time.setprevtime_compat200(999424113)
if os.name == "nt":
prevtimestr = b"2001-09-02T02-48-33-07-00"
else:
prevtimestr = b"2001-09-02T02:48:33-07:00"
t_diff = os.path.join(abs_output_dir, b"out.%s.diff" % prevtimestr)
Globals.postset_regexp_local("no_compression_regexp",
actions.DEFAULT_NOT_COMPRESSED_REGEXP, re.I)
class inctest(unittest.TestCase):
"""Test the incrementRP function"""
def setUp(self):
Globals.set('isbackup_writer', 1)
MakeOutputDir()
def check_time(self, rp):
"""Make sure that rp is an inc file, and time is Time.prevtime"""
self.assertTrue(rp.isincfile())
t = rp.getinctime()
self.assertEqual(t, Time.prevtime)
def testreg(self):
"""Test increment of regular files"""
Globals.compression = None
target.setdata()
if target.lstat():
target.delete()
rpd = rpath.RPath(lc, t_diff)
if rpd.lstat():
rpd.delete()
diffrp = increment.Increment(rf, exec1, target)
self.assertTrue(diffrp.isreg())
self.assertTrue(
diffrp._equal_verbose(exec1, check_index=0, compare_size=0))
self.check_time(diffrp)
self.assertEqual(diffrp.getinctype(), b'diff')
diffrp.delete()
def testmissing(self):
"""Test creation of missing files"""
missing_rp = increment.Increment(rf, nothing, target)
self.check_time(missing_rp)
self.assertEqual(missing_rp.getinctype(), b'missing')
missing_rp.delete()
@unittest.skipIf(os.name == "nt", "Symlinks not supported under Windows")
def testsnapshot(self):
"""Test making of a snapshot"""
Globals.compression = None
snap_rp = increment.Increment(rf, sym, target)
self.check_time(snap_rp)
self.assertTrue(rpath._cmp_file_attribs(snap_rp, sym))
self.assertTrue(rpath.cmp(snap_rp, sym))
snap_rp.delete()
snap_rp2 = increment.Increment(sym, rf, target)
self.check_time(snap_rp2)
self.assertTrue(snap_rp2._equal_verbose(rf, check_index=0))
self.assertTrue(rpath.cmp(snap_rp2, rf))
snap_rp2.delete()
@unittest.skipIf(os.name == "nt", "Symlinks not supported under Windows")
def testGzipsnapshot(self):
"""Test making a compressed snapshot"""
Globals.compression = 1
rp = increment.Increment(rf, sym, target)
self.check_time(rp)
self.assertTrue(rp._equal_verbose(sym, check_index=0, compare_size=0))
self.assertTrue(rpath.cmp(rp, sym))
rp.delete()
rp = increment.Increment(sym, rf, target)
self.check_time(rp)
self.assertTrue(rp._equal_verbose(rf, check_index=0, compare_size=0))
with rp.open("rb", 1) as rp_fd, rf.open("rb") as rf_fd:
self.assertTrue(rpath._cmp_file_obj(rp_fd, rf_fd))
self.assertTrue(rp.isinccompressed())
rp.delete()
@unittest.skipIf(os.name == "nt", "Symlinks not supported under Windows")
def testdir(self):
"""Test increment on base_dir"""
rp = increment.Increment(sym, base_dir, target)
self.check_time(rp)
self.assertTrue(rp.lstat())
self.assertTrue(target.isdir())
self.assertTrue(base_dir._equal_verbose(rp, check_index=0,
compare_size=0,
compare_type=0))
self.assertTrue(rp.isreg())
rp.delete()
target.delete()
def testDiff(self):
"""Test making diffs"""
Globals.compression = None
rp = increment.Increment(rf, rf2, target)
self.check_time(rp)
self.assertTrue(rp._equal_verbose(rf2, check_index=0, compare_size=0))
Rdiff.patch_local(rf, rp, out2)
self.assertTrue(rpath.cmp(rf2, out2))
rp.delete()
out2.delete()
def testGzipDiff(self):
"""Test making gzipped diffs"""
Globals.compression = 1
rp = increment.Increment(rf, rf2, target)
self.check_time(rp)
self.assertTrue(rp._equal_verbose(rf2, check_index=0, compare_size=0))
Rdiff.patch_local(rf, rp, out2, delta_compressed=1)
self.assertTrue(rpath.cmp(rf2, out2))
rp.delete()
out2.delete()
def testGzipRegexp(self):
"""Here a .gz file shouldn't be compressed"""
Globals.compression = 1
rpath.copy(rf, out_gz)
self.assertTrue(out_gz.lstat())
rp = increment.Increment(rf, out_gz, target)
self.check_time(rp)
self.assertTrue(
rp._equal_verbose(out_gz, check_index=0, compare_size=0))
Rdiff.patch_local(rf, rp, out2)
self.assertTrue(rpath.cmp(out_gz, out2))
rp.delete()
out2.delete()
out_gz.delete()
if __name__ == '__main__':
unittest.main()
|