25
from stat import ST_MODE, S_ISDIR, ST_SIZE
25
from stat import ST_MODE, S_ISDIR, ST_SIZE, S_IMODE
28
from bzrlib.osutils import (abspath, realpath, normpath, pathjoin, rename,
32
from bzrlib.osutils import (abspath, realpath, normpath, pathjoin, rename,
29
33
check_legal_path, rmtree)
30
34
from bzrlib.symbol_versioning import warn
31
35
from bzrlib.trace import mutter
32
36
from bzrlib.transport import Transport, Server
33
import bzrlib.urlutils as urlutils
39
_append_flags = os.O_CREAT | os.O_APPEND | os.O_WRONLY | osutils.O_BINARY
36
42
class LocalTransport(Transport):
52
58
super(LocalTransport, self).__init__(base)
53
59
self._local_base = urlutils.local_path_from_url(base)
54
## mutter("_local_base: %r => %r", base, self._local_base)
56
61
def should_cache(self):
162
167
"""Create a directory at the given path."""
171
# os.mkdir() will filter through umask
165
175
path = self._abspath(relpath)
176
os.mkdir(path, local_mode)
167
177
if mode is not None:
178
# It is probably faster to just do the chmod, rather than
179
# doing a stat, and then trying to compare
168
180
os.chmod(path, mode)
169
181
except (IOError, OSError),e:
170
182
self._translate_error(e, path)
172
184
def append(self, relpath, f, mode=None):
173
185
"""Append the text in the file-like object into the final location."""
174
186
abspath = self._abspath(relpath)
178
fp = open(abspath, 'ab')
179
# FIXME should we really be chmodding every time ? RBC 20060523
181
os.chmod(abspath, mode)
182
except (IOError, OSError),e:
183
self._translate_error(e, relpath)
184
# win32 workaround (tell on an unwritten file returns 0)
188
# os.open() will automatically use the umask
193
fd = os.open(abspath, _append_flags, local_mode)
194
except (IOError, OSError),e:
195
self._translate_error(e, relpath)
199
if mode is not None and mode != S_IMODE(st.st_mode):
200
# Because of umask, we may still need to chmod the file.
201
# But in the general case, we won't have to
202
os.chmod(abspath, mode)
203
self._pump_to_fd(f, fd)
208
def _pump_to_fd(self, fromfile, to_fd):
209
"""Copy contents of one file to another."""
212
b = fromfile.read(BUFSIZE)
193
217
def copy(self, rel_from, rel_to):
194
218
"""Copy the item at rel_from to the location at rel_to"""
195
219
path_from = self._abspath(rel_from)