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/>.
20
# Test how well we handle user mucking with files while we back up
24
sys.path.insert(0, sys.path[0]+'/..')
32
def rewrite(name, size):
35
string = ('{:%s<%d}' % (last_written, size)).format('')
38
last_written = chr(ord(last_written) + 1) if last_written != 'z' else 'a'
40
def keep_writing(destdir, sourcename):
42
rewrite(sourcename, 30 * 1024 * 1024)
43
assert ldtp.waittillguiexist('frmBackUp')
44
while ldtp.guiexist('frmBackUp'):
45
rewrite(sourcename, 30 * 1024 * 1024)
49
def wait_for_volume(destdir):
51
while len(os.listdir(destdir)) < 2 and count < 200:
59
sourcedir = base.get_temp_name('source')
60
os.makedirs(sourcedir)
61
sourcefile = os.path.join(sourcedir, 'file')
62
base.backup_simple(backend='file', includes=[sourcedir], finish=False)
64
destdir = base.get_temp_name('local')
65
keep_writing(destdir, sourcefile)
67
restoredir = base.get_temp_name('restore')
68
restorefile = os.path.join(restoredir, './'+sourcefile)
69
base.restore_simple(restoredir)
71
# make sure that whatever version of the file got written, got written complete
72
f = open(restorefile, 'rb')
75
assert re.match('^%c+$' % string[0], string), string
81
sourcedir = base.get_temp_name('source')
82
os.makedirs(sourcedir)
84
rewrite(os.path.join(sourcedir, 'a'), 20)
85
rewrite(os.path.join(sourcedir, 'b'), 30 * 1024 * 1024)
86
rewrite(os.path.join(sourcedir, 'c'), 30)
88
base.backup_simple(backend='file', includes=[sourcedir], finish=False)
90
destdir = base.get_temp_name('local')
91
wait_for_volume(destdir)
92
ldtp.click('frmBackUp', 'btnResumeLater')
94
rewrite(os.path.join(sourcedir, 'a'), 20)
98
restoredir = base.get_temp_name('restore')
99
restorefile = os.path.join(restoredir, './'+sourcedir, 'a')
100
base.restore_simple(restoredir)
102
f = open(restorefile, 'rb')
105
assert len(string) == 20, string
106
assert re.match('^d+$', string), string
112
sourcedir = base.get_temp_name('source')
113
os.makedirs(sourcedir)
115
rewrite(os.path.join(sourcedir, 'a'), 20)
116
rewrite(os.path.join(sourcedir, 'b'), 30 * 1024 * 1024)
117
rewrite(os.path.join(sourcedir, 'c'), 30)
119
base.backup_simple(backend='file', includes=[sourcedir], finish=False)
121
destdir = base.get_temp_name('local')
122
wait_for_volume(destdir)
123
ldtp.click('frmBackUp', 'btnResumeLater')
125
rewrite(os.path.join(sourcedir, 'b'), 30 * 1024 * 1024)
129
restoredir = base.get_temp_name('restore')
130
restorefile = os.path.join(restoredir, './'+sourcedir, 'b')
131
base.restore_simple(restoredir)
133
f = open(restorefile, 'rb')
136
assert len(string) == 30 * 1024 * 1024, string[0:1024]
137
assert re.match('^d+$', string), string[0:1024]
140
base.run(pause_before)
141
base.run(pause_middle)