Rev 4739: (vila, in file:///home/pqm/archives/thelove/bzr/2.0/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Mar 3 10:28:31 GMT 2010
At file:///home/pqm/archives/thelove/bzr/2.0/
------------------------------------------------------------
revno: 4739 [merge]
revision-id: pqm at pqm.ubuntu.com-20100303102830-65cu66torg2offly
parent: pqm at pqm.ubuntu.com-20100301164210-xxeli4qqjkkli083
parent: v.ladeuil+lp at free.fr-20100303092147-on0gefi6tccvm2v6
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.0
timestamp: Wed 2010-03-03 10:28:30 +0000
message:
(vila,
for songofacandy) Use O_NOINHERIT to avoid PermissionDenied errors
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-01 15:30:54 +0000
+++ b/NEWS 2010-03-03 09:21:47 +0000
@@ -44,6 +44,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 2009-10-08 03:55:30 +0000
+++ b/bzrlib/osutils.py 2010-03-03 09:13:32 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006, 2007, 2009 Canonical Ltd
+# Copyright (C) 2005-2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -74,8 +74,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():
@@ -639,7 +642,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)
@@ -1907,3 +1910,46 @@
if use_cache:
_cached_concurrency = concurrency
return concurrency
+
+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 2009-06-23 01:59:20 +0000
+++ b/bzrlib/transport/local.py 2010-02-23 02:49:20 +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