2
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 2; coding: utf-8 -*-
4
# This file is part of Déjà Dup.
5
# For copyright information, see AUTHORS.
7
# Déjà Dup is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
12
# Déjà Dup is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with Déjà Dup. If not, see <http://www.gnu.org/licenses/>.
24
sys.path.insert(0, sys.path[0]+'/..')
28
BASEPATH = '/tmp/deja-dup-test/'
30
def check_dir(path, oneval):
32
assert base.file_equals(root+'one', oneval)
33
assert base.file_equals(root+'two', 'two\n')
34
assert base.file_equals(root+'three', 'three\n')
35
assert base.file_equals(root+'top/one', 'one\n')
36
assert os.path.isdir(root+'top/next')
39
restoredir = base.get_temp_name('restore', make=True)
40
os.chmod(restoredir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) # give new root all permissions
41
os.chmod(base.temp_dir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) # and parent of new root
42
before = os.stat(restoredir)
43
beforeparent = os.stat(base.temp_dir)
45
DATE1 = subprocess.Popen(['date', '-d', '2009-08-01 21:14:21', '+%x %X'], stdout=subprocess.PIPE).communicate()[0].strip()
46
DATE2 = subprocess.Popen(['date', '-d', '2009-08-01 21:14:34', '+%x %X'], stdout=subprocess.PIPE).communicate()[0].strip()
47
DATE3 = subprocess.Popen(['date', '-d', '2009-08-01 21:14:41', '+%x %X'], stdout=subprocess.PIPE).communicate()[0].strip()
48
base.restore_simple(restoredir, date=DATE1, backend='file', dest=(sys.path[0]+'/vols/simple'), encrypt=None)
49
# A concern is that DD will overwrite the permissions of the restore directory or its parents, so check that here
50
after = os.stat(restoredir)
51
assert before.st_mode == after.st_mode, after.st_mode
52
assert before.st_uid == after.st_uid, after.st_uid
53
assert before.st_gid == after.st_gid, after.st_gid
54
afterparent = os.stat(base.temp_dir)
55
assert beforeparent.st_mode == afterparent.st_mode, afterparent.st_mode
56
assert beforeparent.st_uid == afterparent.st_uid, afterparent.st_uid
57
assert beforeparent.st_gid == afterparent.st_gid, afterparent.st_gid
58
check_dir(restoredir, 'one\n')
59
os.system("rm -r %s" % restoredir)
60
base.restore_simple(restoredir, DATE2, encrypt=None)
61
check_dir(restoredir, 'one1\n')
62
os.system("rm -r %s" % restoredir)
63
base.restore_simple(restoredir, DATE3, encrypt=None)
64
check_dir(restoredir, 'one1!\n')