Exemple #1
0
def Regress(mirror_rp):
    """Bring mirror and inc directory back to regress_to_time

    Also affects the rdiff-backup-data directory, so Globals.rbdir
    should be set.  Regress should only work one step at a time
    (i.e. don't "regress" through two separate backup sets.  This
    function should be run locally to the rdiff-backup-data directory.

    """
    inc_rpath = Globals.rbdir.append_path(b"increments")
    assert mirror_rp.index == () and inc_rpath.index == (), (
        "Mirror and increment paths must have an empty index")
    assert mirror_rp.isdir() and inc_rpath.isdir(), (
        "Mirror and increments paths must be directories")
    assert mirror_rp.conn is inc_rpath.conn is Globals.local_connection, (
        "Regress must happen locally.")
    meta_manager, former_current_mirror_rp = _set_regress_time()
    _set_restore_times()
    _regress_rbdir(meta_manager)
    ITR = rorpiter.IterTreeReducer(RegressITRB, [])
    for rf in _iterate_meta_rfs(mirror_rp, inc_rpath):
        ITR(rf.index, rf)
    ITR.finish_processing()
    if former_current_mirror_rp:
        if Globals.do_fsync:
            C.sync()  # Sync first, since we are marking dest dir as good now
        former_current_mirror_rp.delete()
Exemple #2
0
 def test_acl_quoting(self):
     """Test the acl_quote and acl_unquote functions"""
     self.assertEqual(C.acl_quote(b'foo'), b'foo')
     self.assertEqual(C.acl_quote(b'\n'), b'\\012')
     self.assertEqual(C.acl_unquote(b'\\012'), b'\n')
     s = b'\\\n\t\145\n\01=='
     self.assertEqual(C.acl_unquote(C.acl_quote(s)), s)
Exemple #3
0
    def _object_to_record(ea):
        """Convert ExtendedAttributes object to text record"""
        str_list = [b'# file: %s' % C.acl_quote(ea.get_indexpath())]

        for (name, val) in ea.attr_dict.items():
            if not val:
                str_list.append(name)
            else:
                encoded_val = base64.b64encode(val)
                str_list.append(b'%s=0s%s' % (C.acl_quote(name), encoded_val))
        return b'\n'.join(str_list) + b'\n'
Exemple #4
0
	def test_strlong(self):
		"""Test str2long and long2str"""
		self.assertRaises(TypeError, C.long2str, "hello")
		self.assertRaises(TypeError, C.str2long, 34)
		self.assertRaises(TypeError, C.str2long, "oeuo")
		self.assertRaises(TypeError, C.str2long, "oeuoaoeuaoeu")

		for s in ["\0\0\0\0\0\0\0", "helloto",
				  "\xff\xff\xff\xff\xff\xff\xff", "randoms"]:
			assert len(s) == 7, repr(s)
			s_out = C.long2str(C.str2long(s))
			assert s_out == s, (s_out, C.str2long(s), s)
		for l in 0L, 1L, 4000000000L, 34234L, 234234234L:
			assert C.str2long(C.long2str(l)) == l
Exemple #5
0
def backup_remove_curmirror_local():
    """Remove the older of the current_mirror files.  Use at end of session"""
    assert Globals.rbdir.conn is Globals.local_connection, (
        "Function can only be called locally and not over '{conn}'.".format(
            conn=Globals.rbdir.conn))
    curmir_incs = restore.get_inclist(Globals.rbdir.append(b"current_mirror"))
    assert len(curmir_incs) == 2, (
        "There must be two current mirrors not '{ilen}'.".format(
            ilen=len(curmir_incs)))
    if curmir_incs[0].getinctime() < curmir_incs[1].getinctime():
        older_inc = curmir_incs[0]
    else:
        older_inc = curmir_incs[1]
    if Globals.do_fsync:
        C.sync()  # Make sure everything is written before curmirror is removed
    older_inc.delete()
Exemple #6
0
    def test_strlong(self):
        """Test str2long and long2str"""
        self.assertRaises(TypeError, C.long2str, "hello")
        self.assertRaises(TypeError, C.str2long, 34)
        self.assertRaises(TypeError, C.str2long, "oeuo")
        self.assertRaises(TypeError, C.str2long, "oeuoaoeuaoeu")

        for s in [
                "\0\0\0\0\0\0\0", "helloto", "\xff\xff\xff\xff\xff\xff\xff",
                "randoms"
        ]:
            assert len(s) == 7, repr(s)
            s_out = C.long2str(C.str2long(s))
            assert s_out == s, (s_out, C.str2long(s), s)
        for l in 0L, 1L, 4000000000L, 34234L, 234234234L:
            assert C.str2long(C.long2str(l)) == l
Exemple #7
0
    def _record_to_object(record):
        """Convert text record to ExtendedAttributes object"""
        lines = record.split(b'\n')
        first = lines.pop(0)
        if not first[:8] == b'# file: ':
            raise meta.ParsingError("Bad record beginning: %r" % first[:8])
        filename = first[8:]
        if filename == b'.':
            index = ()
        else:
            unquoted_filename = C.acl_unquote(filename)
            index = tuple(unquoted_filename.split(b'/'))
        ea = get_meta_object(index)

        for line in lines:
            line = line.strip()
            if not line:
                continue
            if line[0] == b'#':
                raise meta.ParsingError(
                    "Only the first line of a record can start with a hash: {line}."
                    .format(line=line))
            eq_pos = line.find(b'=')
            if eq_pos == -1:
                ea.set(line)
            else:
                name = line[:eq_pos]
                if line[eq_pos + 1:eq_pos + 3] != b'0s':
                    raise meta.ParsingError(
                        "Currently only base64 encoding supported")
                encoded_val = line[eq_pos + 3:]
                ea.set(name, base64.b64decode(encoded_val))
        return ea
Exemple #8
0
 def test_acl_quoting(self):
     """Test the acl_quote and acl_unquote functions"""
     assert C.acl_quote(b'foo') == b'foo', C.acl_quote(b'foo')
     assert C.acl_quote(b'\n') == b'\\012', C.acl_quote(b'\n')
     assert C.acl_unquote(b'\\012') == b'\n'
     s = b'\\\n\t\145\n\01=='
     assert C.acl_unquote(C.acl_quote(s)) == s
Exemple #9
0
	def test_acl_quoting(self):
		"""Test the acl_quote and acl_unquote functions"""
		assert C.acl_quote('foo') == 'foo', C.acl_quote('foo')
		assert C.acl_quote('\n') == '\\012', C.acl_quote('\n')
		assert C.acl_unquote('\\012') == '\n'
		s = '\\\n\t\145\n\01=='
		assert C.acl_unquote(C.acl_quote(s)) == s
Exemple #10
0
 def _record_to_object(record):
     """Convert text record to an AccessControlLists object"""
     newline_pos = record.find(b'\n')
     first_line = record[:newline_pos]
     if not first_line.startswith(b'# file: '):
         raise meta.ParsingError("Bad record beginning: %r" % first_line)
     filename = first_line[8:]
     if filename == b'.':
         index = ()
     else:
         unquoted_filename = C.acl_unquote(filename)
         index = tuple(unquoted_filename.split(b'/'))
     return get_meta_object(index, os.fsdecode(record[newline_pos:]))
Exemple #11
0
	def test_make_dict(self):
		"""Test making stat dictionaries"""
		rp1 = RPath(Globals.local_connection, "/dev/ttyS1")
		rp2 = RPath(Globals.local_connection, "./ctest.py")
		rp3 = RPath(Globals.local_connection, "aestu/aeutoheu/oeu")
		rp4 = RPath(Globals.local_connection, "testfiles/various_file_types/symbolic_link")
		rp5 = RPath(Globals.local_connection, "testfiles/various_file_types/fifo")

		for rp in [rp1, rp2, rp3, rp4, rp5]:
			dict1 = rp.make_file_dict_old()
			dict2 = C.make_file_dict(rp.path)
			if dict1 != dict2:
				print "Python dictionary: ", dict1
				print "not equal to C dictionary: ", dict2
				print "for path ", rp.path
				assert 0
Exemple #12
0
    def from_string(self, acl_str):
        def _safe_str(cmd):
            """Transform bytes into string without risk of conversion error"""
            if isinstance(cmd, str):
                return cmd
            else:
                return str(cmd, errors='replace')

        lines = acl_str.splitlines()
        if len(lines) != 2 or not lines[0][:8] == b"# file: ":
            raise meta.ParsingError("Bad record beginning: %s" %
                                    _safe_str(lines[0][:8]))
        filename = lines[0][8:]
        if filename == b'.':
            self.index = ()
        else:
            self.index = tuple(C.acl_unquote(filename).split(b'/'))
        self.__acl = lines[1]
Exemple #13
0
    def test_make_dict(self):
        """Test making stat dictionaries"""
        rp1 = RPath(Globals.local_connection, "/dev/ttyS1")
        rp2 = RPath(Globals.local_connection, "./ctest.py")
        rp3 = RPath(Globals.local_connection, "aestu/aeutoheu/oeu")
        rp4 = RPath(Globals.local_connection,
                    "testfiles/various_file_types/symbolic_link")
        rp5 = RPath(Globals.local_connection,
                    "testfiles/various_file_types/fifo")

        for rp in [rp1, rp2, rp3, rp4, rp5]:
            dict1 = rp.make_file_dict_old()
            dict2 = C.make_file_dict(rp.path)
            if dict1 != dict2:
                print "Python dictionary: ", dict1
                print "not equal to C dictionary: ", dict2
                print "for path ", rp.path
                assert 0
Exemple #14
0
 def __bytes__(self):
     return b'# file: %b\n%b\n' % \
         (C.acl_quote(self.get_indexpath()), self.__acl)
Exemple #15
0
 def _filename_to_index(self, filename):
     """Convert possibly quoted filename to index tuple"""
     if filename == b'.':
         return ()
     else:
         return tuple(C.acl_unquote(filename).split(b'/'))
Exemple #16
0
 def test_acl_quoting_equals(self):
     """Make sure the equals character is quoted"""
     self.assertNotEqual(C.acl_quote(b'='), b'=')
Exemple #17
0
 def test_acl_quoting_equals(self):
     """Make sure the equals character is quoted"""
     assert C.acl_quote(b'=') != b'='
Exemple #18
0
 def test_acl_quoting2(self):
     """This string used to segfault the quoting code, try now"""
     s = b'\xd8\xab\xb1Wb\xae\xc5]\x8a\xbb\x15v*\xf4\x0f!\xf9>\xe2Y\x86\xbb\xab\xdbp\xb0\x84\x13k\x1d\xc2\xf1\xf5e\xa5U\x82\x9aUV\xa0\xf4\xdf4\xba\xfdX\x03\x82\x07s\xce\x9e\x8b\xb34\x04\x9f\x17 \xf4\x8f\xa6\xfa\x97\xab\xd8\xac\xda\x85\xdcKvC\xfa#\x94\x92\x9e\xc9\xb7\xc3_\x0f\x84g\x9aB\x11<=^\xdbM\x13\x96c\x8b\xa7|*"\\\'^$@#!(){}?+ ~` '
     quoted = C.acl_quote(s)
     assert C.acl_unquote(quoted) == s
Exemple #19
0
	def test_acl_quoting_equals(self):
		"""Make sure the equals character is quoted"""
		assert C.acl_quote('=') != '='
Exemple #20
0
	def test_acl_quoting2(self):
		"""This string used to segfault the quoting code, try now"""
		s = '\xd8\xab\xb1Wb\xae\xc5]\x8a\xbb\x15v*\xf4\x0f!\xf9>\xe2Y\x86\xbb\xab\xdbp\xb0\x84\x13k\x1d\xc2\xf1\xf5e\xa5U\x82\x9aUV\xa0\xf4\xdf4\xba\xfdX\x03\x82\x07s\xce\x9e\x8b\xb34\x04\x9f\x17 \xf4\x8f\xa6\xfa\x97\xab\xd8\xac\xda\x85\xdcKvC\xfa#\x94\x92\x9e\xc9\xb7\xc3_\x0f\x84g\x9aB\x11<=^\xdbM\x13\x96c\x8b\xa7|*"\\\'^$@#!(){}?+ ~` '
		quoted = C.acl_quote(s)
		assert C.acl_unquote(quoted) == s
Exemple #21
0
 def _object_to_record(acl):
     """Convert an AccessControlLists object into a text record"""
     return b'# file: %b\n%b\n' % (C.acl_quote(
         acl.get_indexpath()), os.fsencode(str(acl)))
Exemple #22
0
 def test_sync(self):
     """Test running C.sync"""
     C.sync()
Exemple #23
0
	def test_sync(self):
		"""Test running C.sync"""
		C.sync()