Merge lp:~bialix/bzr/lock-unicode-win32 into lp:~bzr/bzr/trunk-old

Proposed by Alexander Belchenko
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~bialix/bzr/lock-unicode-win32
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 67 lines
To merge this branch: bzr merge lp:~bialix/bzr/lock-unicode-win32
Reviewer Review Type Date Requested Status
John A Meinel Approve
bzr-core Pending
Review via email: mp+8305@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alexander Belchenko (bialix) wrote :

This patch fixes regression in OS locks @ win32 re unicode paths.

Please, merge it to 1.17.

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexander Belchenko wrote:
> Alexander Belchenko has proposed merging lp:~bialix/bzr/lock-unicode-win32 into lp:bzr.
>
> Requested reviews:
> John A Meinel (jameinel)
> bzr-core (bzr-core)
>
> This patch fixes regression in OS locks @ win32 re unicode paths.
>
> Please, merge it to 1.17.
>

  Review: approve

This seems fine, though I'll note that we haven't use 'os.path.sup..' in
the past to determine W versus A. Why not use:

   # for Windows NT/2K/XP/etc vs Windows 98
   win32file_CreateFile = getattr(win32file, 'CreateFileW',
      win32file.CreateFile)

Also, I thought we used ctypes preferentially to win32file, since that
was "already present in python 2.5", do we need fixes on the ctypes side
as well?

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpTUB8ACgkQJdeBCYSNAAPt4wCgyg9SKrgwgdy3KpHIT5B6smPP
k9MAoKG5xtvbcKDmDidPAYOQUoEH+QGu
=Ggvf
-----END PGP SIGNATURE-----

Revision history for this message
Alexander Belchenko (bialix) wrote :

John A Meinel пишет:
> Review: approve

Can you merge it, please?

> This seems fine, though I'll note that we haven't use 'os.path.sup..' in
> the past to determine W versus A. Why not use:
>
> # for Windows NT/2K/XP/etc vs Windows 98
> win32file_CreateFile = getattr(win32file, 'CreateFileW',
> win32file.CreateFile)

Because 'CreateFileW' function present even on Windows 98, but it cannot
be actually called.

os.path.supports_unicode_filenames is uised in lock.py in the code
related to ctypes-based locks. So my patch is basically do the same for
win32file-based locks as it works today (in bzr.dev) for ctypes-based locks.

> Also, I thought we used ctypes preferentially to win32file, since that
> was "already present in python 2.5", do we need fixes on the ctypes side
> as well?

As I could see we prefer win32file-based locks, because by default first
defined locks implementation is used by bzrlib API, and win32file-based
is first implementation for win32. IIUC bzr prefer win32file because
it's a C extension around Win32 API, while ctypes is universal FFI and
therefore slower (at least from theory).

Also ctypes-based implementation uses unicode API on Windows NT, and it
successfully passed new unicode tests.

Revision history for this message
John A Meinel (jameinel) :
review: Approve
Revision history for this message
Martin Pool (mbp) wrote :

I'll merge it

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/lock.py'
2--- bzrlib/lock.py 2009-06-19 10:04:02 +0000
3+++ bzrlib/lock.py 2009-07-07 17:35:09 +0000
4@@ -301,13 +301,19 @@
5
6
7 if have_pywin32 and sys.platform == 'win32':
8+ if os.path.supports_unicode_filenames:
9+ # for Windows NT/2K/XP/etc
10+ win32file_CreateFile = win32file.CreateFileW
11+ else:
12+ # for Windows 98
13+ win32file_CreateFile = win32file.CreateFile
14
15 class _w32c_FileLock(_OSLock):
16
17 def _open(self, filename, access, share, cflags, pymode):
18 self.filename = osutils.realpath(filename)
19 try:
20- self._handle = win32file.CreateFile(filename, access, share,
21+ self._handle = win32file_CreateFile(filename, access, share,
22 None, win32file.OPEN_ALWAYS,
23 win32file.FILE_ATTRIBUTE_NORMAL, None)
24 except pywintypes.error, e:
25
26=== modified file 'bzrlib/tests/per_lock/__init__.py'
27--- bzrlib/tests/per_lock/__init__.py 2009-03-23 14:59:43 +0000
28+++ bzrlib/tests/per_lock/__init__.py 2009-07-07 17:35:09 +0000
29@@ -39,7 +39,6 @@
30 return result
31
32
33-
34 def load_tests(standard_tests, module, loader):
35 submod_tests = loader.loadTestsFromModuleNames([
36 'bzrlib.tests.per_lock.test_lock',
37
38=== modified file 'bzrlib/tests/per_lock/test_lock.py'
39--- bzrlib/tests/per_lock/test_lock.py 2009-03-23 14:59:43 +0000
40+++ bzrlib/tests/per_lock/test_lock.py 2009-07-07 17:35:10 +0000
41@@ -21,6 +21,7 @@
42 osutils,
43 )
44
45+from bzrlib.tests import UnicodeFilenameFeature
46 from bzrlib.tests.per_lock import TestCaseWithLock
47
48
49@@ -160,3 +161,18 @@
50 b_lock.unlock()
51 if c_lock is not None:
52 c_lock.unlock()
53+
54+
55+class TestLockUnicodePath(TestCaseWithLock):
56+
57+ _test_needs_features = [UnicodeFilenameFeature]
58+
59+ def test_read_lock(self):
60+ self.build_tree([u'\u1234'])
61+ u_lock = self.read_lock(u'\u1234')
62+ self.addCleanup(u_lock.unlock)
63+
64+ def test_write_lock(self):
65+ self.build_tree([u'\u1234'])
66+ u_lock = self.write_lock(u'\u1234')
67+ self.addCleanup(u_lock.unlock)