[PATCH 1 of 1 RFC] scmutil: eliminate util.samestat

Adrian Buehlmann adrian at cadifra.com
Tue Jun 12 18:46:03 CDT 2012


On 2012-06-13 01:16, Matt Mackall wrote:
> On Wed, 2012-06-13 at 01:03 +0200, Adrian Buehlmann wrote:
>> On 2012-06-13 00:32, Adrian Buehlmann wrote:
>>> On 2012-06-13 00:04, Matt Mackall wrote:
>>>> On Sat, 2012-06-09 at 11:58 +0200, Adrian Buehlmann wrote:
>>>>> # HG changeset patch
>>>>> # User Adrian Buehlmann <adrian at cadifra.com>
>>>>> # Date 1339182525 -7200
>>>>> # Node ID 48649541c9a2002a148699136cff71865b18dc60
>>>>> # Parent  2255950e1f7663a9faa6b57040cc5c0debe7d4dd
>>>>> scmutil: eliminate util.samestat
>>>>>
>>>>> It's impossible to implement that on Windows.
>>>>
>>>> First, I don't know why that in itself is an argument for removing it.
>>>> We have plenty of utility functions that are only relevant to one
>>>> platform.
>>>>
>>>> Second, I don't believe it's impossible to implement and happen to know
>>>> that analogous functions exist. For instance, GetFileInformationByHandle
>>>> has fields that would serve the same purpose (volume serial number and
>>>> file index):
>>>>
>>>>  http://msdn.microsoft.com/en-us/library/aa363788%28VS.85%29.aspx
>>>>
>>>
>>> That works only for files, for directories, samestat is impossible.
> 
> ...
> 
>> $ python
>> Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> from mercurial import win32
>>>>> win32.samefile('C:/Users/adi', 'C:/Users/adi')
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>>   File "mercurial\win32.py", line 220, in samefile
>>     res1 = _getfileinfo(fpath1)
>>   File "mercurial\win32.py", line 197, in _getfileinfo
>>     _raiseoserror(name)
>>   File "mercurial\win32.py", line 190, in _raiseoserror
>>     raise OSError(err.errno, '%s: %s' % (name, err.strerror))
>> OSError: [Errno 13] C:/Users/adi: Access is denied.
> 
> See here:
> 
> http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%
> 28v=vs.85%29.aspx
> 
> Grep for "FILE_FLAG_BACKUP_SEMANTICS".
> 

Thanks!

I've applied

diff --git a/mercurial/win32.py b/mercurial/win32.py
--- a/mercurial/win32.py
+++ b/mercurial/win32.py
@@ -59,6 +59,8 @@

 _OPEN_EXISTING = 3

+_FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
+
 # SetFileAttributes
 _FILE_ATTRIBUTE_NORMAL = 0x80
 _FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x2000
@@ -192,7 +194,7 @@
 def _getfileinfo(name):
     fh = _kernel32.CreateFileA(name, 0,
             _FILE_SHARE_READ | _FILE_SHARE_WRITE | _FILE_SHARE_DELETE,
-            None, _OPEN_EXISTING, 0, None)
+            None, _OPEN_EXISTING, _FILE_FLAG_BACKUP_SEMANTICS, None)
     if fh == _INVALID_HANDLE_VALUE:
         _raiseoserror(name)
     try:

and then

$ python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from mercurial import win32
>>> win32.samefile('C:/Users/adi', 'C:/Users/adi')
True
>>> win32.samefile('C:/Users/adi', 'C:/Users')
False
>>>

Awesome.

I think with this information we might probably be able to fix
issue2167 (and have a working scmutil.canonpath on Windows).




More information about the Mercurial-devel mailing list