40
41
return possible_prefix
43
def do_directory(tt, trans_id, relative_path, path):
44
def do_directory(tt, trans_id, tree, relative_path, path):
44
45
if isdir(path) and tree.path2id(relative_path) is not None:
45
46
tt.cancel_deletion(trans_id)
63
64
tar_file = tarfile.open('lala', 'r', tar_input)
64
65
prefix = common_directory(tar_file.getnames())
66
66
tt = TreeTransform(tree)
68
69
for path, entry in tree.inventory.iter_entries():
69
70
trans_id = tt.trans_id_tree_path(path)
70
71
tt.delete_contents(trans_id)
72
75
implied_parents = set()
73
76
for member in tar_file.getmembers():
74
77
relative_path = member.name
79
82
add_implied_parents(implied_parents, relative_path)
80
83
trans_id = tt.trans_id_tree_path(relative_path)
81
added.append(relative_path)
84
added.add(relative_path.rstrip('/'))
82
85
path = tree.abspath(relative_path)
84
87
tt.create_file(file_iterator(tar_file.extractfile(member)),
86
89
elif member.isdir():
87
do_directory(tt, trans_id, relative_path, path)
90
do_directory(tt, trans_id, tree, relative_path, path)
88
91
elif member.issym():
89
92
tt.create_symlink(member.linkname, trans_id)
91
for relative_path in implied_parents.difference(set(added)):
94
for relative_path in implied_parents.difference(added):
92
95
if relative_path == "":
94
97
trans_id = tt.trans_id_tree_path(relative_path)
95
98
path = tree.abspath(relative_path)
96
do_directory(tt, trans_id, relative_path, path)
97
added.append(relative_path)
99
do_directory(tt, trans_id, tree, relative_path, path)
100
added.add(relative_path)
99
102
for conflict in cook_conflicts(resolve_conflicts(tt), tt):
100
103
warning(conflict)
102
update_ids(tree, added)
105
def update_ids(tree, added):
105
update_ids(tree, added, removed)
108
def update_ids(tree, added, removed):
106
109
"""Make sure that all present files files have file_ids.
108
111
# XXX detect renames
109
for path in sorted(added):
110
if tree.path2id(path) is None:
112
new = added.difference(removed)
113
deleted = removed.difference(added)
114
tree.add(sorted(new))
115
tree.remove(sorted(deleted, reverse=True))
114
118
def do_import(source, tree_directory=None):