Rev 2674: Add mode parameter to Transport.open_file_stream. in http://people.ubuntu.com/~robertc/baz2.0/transport
Robert Collins
robertc at robertcollins.net
Sun Aug 5 06:38:19 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/transport
------------------------------------------------------------
revno: 2674
revision-id: robertc at robertcollins.net-20070805053815-jeb19qdogkh5zrq5
parent: robertc at robertcollins.net-20070805025745-eg2qmr8jzsky39y2
committer: Robert Collins <robertc at robertcollins.net>
branch nick: transport-get-file
timestamp: Sun 2007-08-05 15:38:15 +1000
message:
Add mode parameter to Transport.open_file_stream.
modified:
bzrlib/tests/test_transport_implementations.py test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
bzrlib/transport/__init__.py transport.py-20050711165921-4978aa7ce1285ad5
bzrlib/transport/chroot.py chroot.py-20061011104729-0us9mgm97z378vnt-1
bzrlib/transport/decorator.py decorator.py-20060402223305-e913a0f25319ab42
bzrlib/transport/local.py local_transport.py-20050711165921-9b1f142bfe480c24
bzrlib/transport/sftp.py sftp.py-20051019050329-ab48ce71b7e32dfe
=== modified file 'bzrlib/tests/test_transport_implementations.py'
--- a/bzrlib/tests/test_transport_implementations.py 2007-08-05 02:57:45 +0000
+++ b/bzrlib/tests/test_transport_implementations.py 2007-08-05 05:38:15 +0000
@@ -643,6 +643,23 @@
finally:
t.close_file_stream('foo')
+ def test_opening_a_file_stream_can_set_mode(self):
+ t = self.get_transport()
+ if t.is_readonly():
+ return
+ if not t._can_roundtrip_unix_modebits():
+ # Can't roundtrip, so no need to run this test
+ return
+ def check_mode(name, mode, expected):
+ handle = t.open_file_stream(name, mode=mode)
+ t.close_file_stream(name)
+ self.assertTransportMode(t, name, expected)
+ check_mode('mode644', 0644, 0644)
+ check_mode('mode666', 0666, 0666)
+ check_mode('mode600', 0600, 0600)
+ # The default permissions should be based on the current umask
+ check_mode('nomode', None, 0666 & ~osutils.get_umask())
+
def test_copy_to(self):
# FIXME: test: same server to same server (partly done)
# same protocol two servers
=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py 2007-08-05 02:57:45 +0000
+++ b/bzrlib/transport/__init__.py 2007-08-05 05:38:15 +0000
@@ -846,7 +846,7 @@
self.mkdir(path, mode=mode)
return len(self._iterate_over(relpaths, mkdir, pb, 'mkdir', expand=False))
- def open_file_stream(self, relpath):
+ def open_file_stream(self, relpath, mode=None):
"""Open a file stream at relpath.
A file stream is a callback which adds data to the file. Buffering
@@ -856,6 +856,8 @@
:seealso: close_file_stream.
:param relpath: The relative path to the file.
+ :param mode: The mode for the newly created file,
+ None means just use the default
:return: A write callback to add data to the file.
"""
raise NotImplementedError(self.open_file_stream)
=== modified file 'bzrlib/transport/chroot.py'
--- a/bzrlib/transport/chroot.py 2007-08-05 02:57:45 +0000
+++ b/bzrlib/transport/chroot.py 2007-08-05 05:38:15 +0000
@@ -89,6 +89,9 @@
def append_file(self, relpath, f, mode=None):
return self._call('append_file', relpath, f, mode)
+ def _can_roundtrip_unix_modebits(self):
+ return self.server.backing_transport._can_roundtrip_unix_modebits()
+
def clone(self, relpath):
return ChrootTransport(self.server, self.abspath(relpath))
@@ -136,8 +139,8 @@
def mkdir(self, relpath, mode=None):
return self._call('mkdir', relpath, mode)
- def open_file_stream(self, relpath):
- return self._call('open_file_stream', relpath)
+ def open_file_stream(self, relpath, mode=None):
+ return self._call('open_file_stream', relpath, mode)
def put_file(self, relpath, f, mode=None):
return self._call('put_file', relpath, f, mode)
=== modified file 'bzrlib/transport/decorator.py'
--- a/bzrlib/transport/decorator.py 2007-08-05 02:57:45 +0000
+++ b/bzrlib/transport/decorator.py 2007-08-05 05:38:15 +0000
@@ -65,6 +65,10 @@
"""See Transport.append_bytes()."""
return self._decorated.append_bytes(relpath, bytes, mode=mode)
+ def _can_roundtrip_unix_modebits(self):
+ """See Transport._can_roundtrip_unix_modebits()."""
+ return self._decorated._can_roundtrip_unix_modebits()
+
def clone(self, offset=None):
"""See Transport.clone()."""
decorated_clone = self._decorated.clone(offset)
@@ -114,9 +118,9 @@
"""See Transport.mkdir()."""
return self._decorated.mkdir(relpath, mode)
- def open_file_stream(self, relpath):
+ def open_file_stream(self, relpath, mode=None):
"""See Transport.open_file_stream."""
- return self._decorated.open_file_stream(relpath)
+ return self._decorated.open_file_stream(relpath, mode=mode)
def put_file(self, relpath, f, mode=None):
"""See Transport.put_file()."""
=== modified file 'bzrlib/transport/local.py'
--- a/bzrlib/transport/local.py 2007-08-05 02:57:45 +0000
+++ b/bzrlib/transport/local.py 2007-08-05 05:38:15 +0000
@@ -307,10 +307,10 @@
"""Create a directory at the given path."""
self._mkdir(self._abspath(relpath), mode=mode)
- def open_file_stream(self, relpath):
+ def open_file_stream(self, relpath, mode=None):
"""See Transport.open_file_stream."""
# initialise the file
- self.put_bytes_non_atomic(relpath, "")
+ self.put_bytes_non_atomic(relpath, "", mode=mode)
handle = open(self._abspath(relpath), 'wb')
transport._file_streams[self.abspath(relpath)] = handle
return handle.write
=== modified file 'bzrlib/transport/sftp.py'
--- a/bzrlib/transport/sftp.py 2007-08-05 02:57:45 +0000
+++ b/bzrlib/transport/sftp.py 2007-08-05 05:38:15 +0000
@@ -539,14 +539,14 @@
"""Create a directory at the given path."""
self._mkdir(self._remote_path(relpath), mode=mode)
- def open_file_stream(self, relpath):
+ def open_file_stream(self, relpath, mode=None):
"""See Transport.open_file_stream."""
# initialise the file to zero-length
# this is three round trips, but we don't use this
# api more than once per write_group at the moment so
# it is a tolerable overhead. Better would be to truncate
# the file after opening. RBC 20070805
- self.put_bytes_non_atomic(relpath, "")
+ self.put_bytes_non_atomic(relpath, "", mode)
abspath = self._remote_path(relpath)
# TODO: jam 20060816 paramiko doesn't publicly expose a way to
# set the file mode at create time. If it does, use it.
More information about the bazaar-commits
mailing list