Rev 4824: (vila) Merge 2.0 into 2.1 including fix for #524560 in file:///home/pqm/archives/thelove/bzr/2.1/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Mar 5 08:21:07 GMT 2010


At file:///home/pqm/archives/thelove/bzr/2.1/

------------------------------------------------------------
revno: 4824 [merge]
revision-id: pqm at pqm.ubuntu.com-20100305082106-0e13lwd00apytqvj
parent: pqm at pqm.ubuntu.com-20100304202911-iyal0t2qzx8cb22h
parent: v.ladeuil+lp at free.fr-20100305074931-q3tiqxs39fprtd49
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.1
timestamp: Fri 2010-03-05 08:21:06 +0000
message:
  (vila) Merge 2.0 into 2.1 including fix for #524560
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/atomicfile.py           atomicfile.py-20050509044450-dbd24e6c564f7c66
  bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
  bzrlib/transport/local.py      local_transport.py-20050711165921-9b1f142bfe480c24
=== modified file 'NEWS'
--- a/NEWS	2010-03-03 22:59:21 +0000
+++ b/NEWS	2010-03-05 07:49:31 +0000
@@ -401,6 +401,10 @@
   version number along with rest of the help text.
   (Parth Malwankar, #369501)
 
+* Use osutils.O_NOINHERIT for some files on win32 to avoid PermissionDenied
+  errors.
+  (Inada Naoki, #524560)
+
 Documentation
 *************
 

=== modified file 'bzrlib/atomicfile.py'
--- a/bzrlib/atomicfile.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/atomicfile.py	2010-02-22 08:28:41 +0000
@@ -60,7 +60,7 @@
 
         self.realfilename = filename
 
-        flags = os.O_EXCL | os.O_CREAT | os.O_WRONLY
+        flags = os.O_EXCL | os.O_CREAT | os.O_WRONLY | osutils.O_NOINHERIT
         if mode == 'wb':
             flags |= osutils.O_BINARY
         elif mode != 'wt':

=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2010-02-17 17:11:16 +0000
+++ b/bzrlib/osutils.py	2010-03-05 07:49:31 +0000
@@ -85,8 +85,11 @@
 # be opened in binary mode, rather than text mode.
 # On other platforms, O_BINARY doesn't exist, because
 # they always open in binary mode, so it is okay to
-# OR with 0 on those platforms
+# OR with 0 on those platforms.
+# O_NOINHERIT and O_TEXT exists only on win32 too.
 O_BINARY = getattr(os, 'O_BINARY', 0)
+O_TEXT = getattr(os, 'O_TEXT', 0)
+O_NOINHERIT = getattr(os, 'O_NOINHERIT', 0)
 
 
 def get_unicode_argv():
@@ -661,7 +664,7 @@
 def sha_file_by_name(fname):
     """Calculate the SHA1 of a file by reading the full text"""
     s = sha()
-    f = os.open(fname, os.O_RDONLY | O_BINARY)
+    f = os.open(fname, os.O_RDONLY | O_BINARY | O_NOINHERIT)
     try:
         while True:
             b = os.read(f, 1<<16)
@@ -2115,3 +2118,46 @@
         else:
             data, _ = self.encode(object, self.errors)
             self.stream.write(data)
+
+if sys.platform == 'win32':
+    def open_file(filename, mode='r', bufsize=-1):
+        """This function is used to override the ``open`` builtin.
+        
+        But it uses O_NOINHERIT flag so the file handle is not inherited by
+        child processes.  Deleting or renaming a closed file opened with this
+        function is not blocking child processes.
+        """
+        writing = 'w' in mode
+        appending = 'a' in mode
+        updating = '+' in mode
+        binary = 'b' in mode
+
+        flags = O_NOINHERIT
+        # see http://msdn.microsoft.com/en-us/library/yeby3zcb%28VS.71%29.aspx
+        # for flags for each modes.
+        if binary:
+            flags |= O_BINARY
+        else:
+            flags |= O_TEXT
+
+        if writing:
+            if updating:
+                flags |= os.O_RDWR
+            else:
+                flags |= os.O_WRONLY
+            flags |= os.O_CREAT | os.O_TRUNC
+        elif appending:
+            if updating:
+                flags |= os.O_RDWR
+            else:
+                flags |= os.O_WRONLY
+            flags |= os.O_CREAT | os.O_APPEND
+        else: #reading
+            if updating:
+                flags |= os.O_RDWR
+            else:
+                flags |= os.O_RDONLY
+
+        return os.fdopen(os.open(filename, flags), mode, bufsize)
+else:
+    open_file = open

=== modified file 'bzrlib/transport/local.py'
--- a/bzrlib/transport/local.py	2010-02-17 17:11:16 +0000
+++ b/bzrlib/transport/local.py	2010-03-05 07:49:31 +0000
@@ -42,8 +42,8 @@
 from bzrlib.transport import Transport, Server
 
 
-_append_flags = os.O_CREAT | os.O_APPEND | os.O_WRONLY | osutils.O_BINARY
-_put_non_atomic_flags = os.O_CREAT | os.O_TRUNC | os.O_WRONLY | osutils.O_BINARY
+_append_flags = os.O_CREAT | os.O_APPEND | os.O_WRONLY | osutils.O_BINARY | osutils.O_NOINHERIT
+_put_non_atomic_flags = os.O_CREAT | os.O_TRUNC | os.O_WRONLY | osutils.O_BINARY | osutils.O_NOINHERIT
 
 
 class LocalTransport(Transport):
@@ -160,7 +160,7 @@
             transport._file_streams[canonical_url].flush()
         try:
             path = self._abspath(relpath)
-            return open(path, 'rb')
+            return osutils.open_file(path, 'rb')
         except (IOError, OSError),e:
             if e.errno == errno.EISDIR:
                 return LateReadError(relpath)
@@ -329,7 +329,7 @@
         # initialise the file
         self.put_bytes_non_atomic(relpath, "", mode=mode)
         abspath = self._abspath(relpath)
-        handle = open(abspath, 'wb')
+        handle = osutils.open_file(abspath, 'wb')
         if mode is not None:
             self._check_mode_and_size(abspath, handle.fileno(), mode)
         transport._file_streams[self.abspath(relpath)] = handle




More information about the bazaar-commits mailing list