1
# Copyright (C) 2005, 2006, 2008, 2009, 2010 Canonical Ltd
1
# Copyright (C) 2005-2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
26
25
ContentFilterContext,
27
26
filtered_output_bytes,
29
from bzrlib.trace import mutter
32
def dir_exporter(tree, dest, root, subdir, filtered=False,
33
per_file_timestamps=False):
34
"""Export this tree to a new directory.
30
def dir_exporter_generator(tree, dest, root, subdir=None, filtered=False,
31
force_mtime=None, fileobj=None):
32
"""Return a generator that exports this tree to a new directory.
36
34
`dest` should either not exist or should be empty. If it does not exist it
37
35
will be created holding the contents of this tree.
37
:param fileobj: Is not used in this exporter
39
39
:note: If the export fails, the destination directory will be
40
40
left in an incompletely exported state: export is not transactional.
42
mutter('export version %r', tree)
46
45
if e.errno == errno.EEXIST:
47
46
# check if directory empty
48
47
if os.listdir(dest) != []:
49
raise errors.BzrError("Can't export tree to non-empty directory.")
48
raise errors.BzrError(
49
"Can't export tree to non-empty directory.")
52
52
# Iterate everything, building up the files we will want to export, and
67
67
symlink_target = tree.get_symlink_target(ie.file_id)
68
68
os.symlink(symlink_target, fullpath)
70
70
raise errors.BzrError(
71
71
"Failed to create symlink %r -> %r, error: %s"
72
72
% (fullpath, symlink_target, e))
74
74
raise errors.BzrError("don't know how to export {%s} of kind %r" %
75
75
(ie.file_id, ie.kind))
76
78
# The data returned here can be in any order, but we've already created all
78
80
flags = os.O_CREAT | os.O_TRUNC | os.O_WRONLY | getattr(os, 'O_BINARY', 0)
80
81
for (relpath, executable), chunks in tree.iter_files_bytes(to_fetch):
82
83
filters = tree._content_filter_stack(relpath)
92
93
out.writelines(chunks)
95
if per_file_timestamps:
96
mtime = tree.get_file_mtime(tree.path2id(relpath), relpath)
96
if force_mtime is not None:
100
file_id = tree.path2id(relpath)
102
file_id = tree.path2id(osutils.pathjoin(subdir, relpath))
103
mtime = tree.get_file_mtime(file_id, relpath)
99
104
os.utime(fullpath, (mtime, mtime))