49
49
self.assertEquals([], os.listdir("target"))
51
51
def test_symlink(self):
52
self.requireFeature(tests.SymlinkFeature)
52
self.requireFeature(features.SymlinkFeature)
53
53
wt = self.make_branch_and_tree('.')
54
54
os.symlink('source', 'link')
67
67
self.assertPathExists('target/b')
68
68
self.assertPathExists('target/b/c')
70
def test_empty_subdir(self):
71
self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
72
wt = self.make_branch_and_tree('source')
73
wt.add(['a', 'b', 'b/c'])
75
self.build_tree(['target/'])
76
export.export(wt, 'target', format="dir", subdir='')
77
self.assertPathExists('target/a')
78
self.assertPathExists('target/b')
79
self.assertPathExists('target/b/c')
70
81
def test_to_existing_nonempty_dir_fail(self):
71
82
self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
72
83
wt = self.make_branch_and_tree('source')
73
84
wt.add(['a', 'b', 'b/c'])
75
86
self.build_tree(['target/', 'target/foo'])
76
self.assertRaises(errors.BzrError, export.export, wt, 'target', format="dir")
87
self.assertRaises(errors.BzrError,
88
export.export, wt, 'target', format="dir")
78
90
def test_existing_single_file(self):
79
self.build_tree(['dir1/', 'dir1/dir2/', 'dir1/first', 'dir1/dir2/second'])
92
'dir1/', 'dir1/dir2/', 'dir1/first', 'dir1/dir2/second'])
80
93
wtree = self.make_branch_and_tree('dir1')
81
94
wtree.add(['dir2', 'first', 'dir2/second'])
99
112
self.addCleanup(b.unlock)
100
113
tree = b.basis_tree()
101
114
orig_iter_files_bytes = tree.iter_files_bytes
102
116
# Make iter_files_bytes slower, so we provoke mtime skew
103
117
def iter_files_bytes(to_fetch):
104
118
for thing in orig_iter_files_bytes(to_fetch):
135
149
self.assertEqual(a_time, t.stat('a').st_mtime)
136
150
self.assertEqual(b_time, t.stat('b').st_mtime)
152
def test_subdir_files_per_timestamps(self):
153
builder = self.make_branch_builder('source')
154
builder.start_series()
155
foo_time = time.mktime((1999, 12, 12, 0, 0, 0, 0, 0, 0))
156
builder.build_snapshot(None, None, [
157
('add', ('', 'root-id', 'directory', '')),
158
('add', ('subdir', 'subdir-id', 'directory', '')),
159
('add', ('subdir/foo.txt', 'foo-id', 'file', 'content\n'))],
161
builder.finish_series()
162
b = builder.get_branch()
164
self.addCleanup(b.unlock)
165
tree = b.basis_tree()
166
export.export(tree, 'target', format='dir', subdir='subdir',
167
per_file_timestamps=True)
168
t = self.get_transport('target')
169
self.assertEquals(foo_time, t.stat('foo.txt').st_mtime)
139
172
class TarExporterTests(tests.TestCaseWithTransport):
209
242
self.assertRaises(errors.BzrError, export.export, wt, '-',
212
def test_export_tarball(self):
245
def test_export_tarball_generator(self):
213
246
wt = self.make_branch_and_tree('.')
214
247
self.build_tree(['a'])
218
251
ball = tarfile.open(None, "w|", target)
221
export_tarball(wt, ball, "bar")
254
for _ in export_tarball_generator(wt, ball, "bar"):
224
self.assertEquals(["bar/a"], ball.getnames())
258
# Ball should now be closed.
260
ball2 = tarfile.open(None, "r", target)
261
self.addCleanup(ball2.close)
262
self.assertEquals(["bar/a"], ball2.getnames())
228
265
class ZipExporterTests(tests.TestCaseWithTransport):