Rev 46: Handle x mode bit for files and provides default mode bits for in http://bazaar.launchpad.net/%7Ebzr-upload-devs/bzr-upload/trunk

Vincent Ladeuil v.ladeuil+lp at free.fr
Sun Jun 22 17:09:54 BST 2008


At http://bazaar.launchpad.net/%7Ebzr-upload-devs/bzr-upload/trunk

------------------------------------------------------------
revno: 46
revision-id: v.ladeuil+lp at free.fr-20080622160951-45dloyi2l88nt24b
parent: v.ladeuil+lp at free.fr-20080620152655-6yp2oxgg9pijn4dl
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: upload
timestamp: Sun 2008-06-22 18:09:51 +0200
message:
  Handle x mode bit for files and provides default mode bits for
  directories.
  
  * tests/test_upload.py:
  (TestUploadMixin.assertUpPathModeEqual): New helper.
  (TestUploadMixin.chmod_file): New helper.
  (TestUploadMixin.test_create_file_in_subdir): Complete test.
  (TestUploadMixin.test_make_file_executable): New test.
  
  * __init__.py:
  (cmd_upload.run): Cosmetic change.
  (cmd_upload.upload_file): Provide mode bits depending on the
  inventory executable property.
  (cmd_upload.make_remote_dir): Provide defulat mode bits.
  (cmd_upload.make_remote_dir_robustly): Oops, add a FIXME for the
  regression.
modified:
  __init__.py                    __init__.py-20080307145942-xx1xgifrreovahgz-1
  tests/test_upload.py           test_upload.py-20080307145942-xx1xgifrreovahgz-2
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2008-06-19 16:09:02 +0000
+++ b/__init__.py	2008-06-22 16:09:51 +0000
@@ -92,7 +92,7 @@
         changes = wt.changes_from(wt.basis_tree())
 
         if revision is None and  changes.has_changed():
-                raise errors.UncommittedChanges(wt)
+            raise errors.UncommittedChanges(wt)
 
         self.branch = wt.branch
 
@@ -147,12 +147,17 @@
     def get_uploaded_revid(self):
         return self.to_transport.get_bytes(self.bzr_upload_revid_file_name)
 
-    def upload_file(self, relpath, id):
+    def upload_file(self, relpath, id, mode=None):
+        if mode is None:
+            if self.tree.is_executable(id):
+                mode = 0775
+            else:
+                mode = 0664
         if not self.quiet:
             self.outf.write('Uploading %s\n' % relpath)
-        self.to_transport.put_bytes(relpath, self.tree.get_file_text(id))
+        self.to_transport.put_bytes(relpath, self.tree.get_file_text(id), mode)
 
-    def upload_file_robustly(self, relpath, id):
+    def upload_file_robustly(self, relpath, id, mode=None):
         """Upload a file, clearing the way on the remote side.
 
         When doing a full upload, it may happen that a directory exists where
@@ -168,19 +173,19 @@
                 self.to_transport.delete_tree(relpath)
         except errors.PathError:
             pass
-        self.upload_file(relpath, id)
-
-    def make_remote_dir(self, relpath):
-        # XXX: handle mode
-        self.to_transport.mkdir(relpath)
-
-    def make_remote_dir_robustly(self, relpath):
+        self.upload_file(relpath, id, mode)
+
+    def make_remote_dir(self, relpath, mode=None):
+        if mode is None:
+            mode = 0775
+        self.to_transport.mkdir(relpath, mode)
+
+    def make_remote_dir_robustly(self, relpath, mode=None):
         """Create a remote directory, clearing the way on the remote side.
 
         When doing a full upload, it may happen that a file exists where we
         want to create our directory.
         """
-        # XXX: handle mode
         try:
             st = self.to_transport.stat(relpath)
             if not stat.S_ISDIR(st.st_mode):
@@ -190,7 +195,8 @@
                 self.to_transport.delete(relpath)
         except errors.PathError:
             pass
-        self.make_remote_dir(relpath)
+        # FIXME: Errr, what if the remote dir already exists ?
+        self.make_remote_dir(relpath, mode)
 
     def delete_remote_file(self, relpath):
         if not self.quiet:

=== modified file 'tests/test_upload.py'
--- a/tests/test_upload.py	2008-06-19 16:09:02 +0000
+++ b/tests/test_upload.py	2008-06-22 16:09:51 +0000
@@ -15,6 +15,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 import os
+import stat
 import sys
 
 
@@ -143,6 +144,20 @@
     def assertUpFileEqual(self, content, path, base=upload_dir):
         self.assertFileEqual(content, base + path)
 
+    def assertUpPathModeEqual(self, path, expected_mode, base=upload_dir):
+        # FIXME: the tests needing that assertion should depend on the server
+        # ability to handle chmod so that they don't fail (or be skipped)
+        # against servers that can't. Note that some bzrlib transports define
+        # _can_roundtrip_unix_modebits in a incomplete way, this property
+        # should depend on both the client and the server, not the client only.
+        st = os.stat(base + path)
+        mode = st.st_mode & 0777
+        if expected_mode == mode:
+            return
+        raise AssertionError(
+            'For path %s, mode is %s not %s' %
+            (base + path, oct(mode), oct(expected_mode)))
+
     def failIfUpFileExists(self, path, base=upload_dir):
         self.failIfExists(base + path)
 
@@ -165,6 +180,11 @@
         self.set_file_content(name, content, base)
         self.tree.commit('modify file %s' % name)
 
+    def chmod_file(self, name, mode, base=branch_dir):
+        path = base + name
+        os.chmod(path, mode)
+        self.tree.commit('change file %s mode to %s' % (name, oct(mode)))
+
     def delete_any(self, name, base=branch_dir):
         self.tree.remove([name], keep_files=False)
         self.tree.commit('delete %s' % name)
@@ -236,6 +256,7 @@
         self.do_upload()
 
         self.assertUpFileEqual('baz', 'dir/goodbye')
+        self.assertUpPathModeEqual('dir', 0775)
 
     def test_modify_file(self):
         self.make_local_branch()
@@ -339,6 +360,19 @@
 
         self.assertUpFileEqual('bar', 'hello')
 
+    def test_make_file_executable(self):
+        self.make_local_branch()
+        self.add_file('hello', 'foo')
+        self.chmod_file('hello', 0664)
+        self.do_full_upload()
+        self.chmod_file('hello', 0755)
+
+        self.assertUpPathModeEqual('hello', 0664)
+
+        self.do_upload()
+
+        self.assertUpPathModeEqual('hello', 0775)
+
 
 class TestFullUpload(tests.TestCaseWithTransport, TestUploadMixin):
 



More information about the bazaar-commits mailing list