[PATCH STABLE] implement nlinks() for _WIN32 in osutil.c (issue1922)

Adrian Buehlmann adrian at cadifra.com
Sun Jan 23 02:24:57 CST 2011


On 2011-01-23 01:43, Aaron Cohen wrote:
> On Saturday, January 22, 2011, Adrian Buehlmann <adrian at cadifra.com>
>>
>> +       fh = CreateFile(name, 0,
>> +                       FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
>> +                       NULL,
>> +                       OPEN_EXISTING,
>> +                       0,
>> +                       NULL);
> 
> Question: Do you know if this goes through CreateFileA or CreateFileW?
> Does it depend on the compilation environment or is the proper
> preprocessor magic happening somewhere earlier? If it goes through
> CreateFileA, what happens when you call nlinks on a file with
> non-ascii chars in its name?

I haven't investigated this, but it calls the same function (CreateFile)
as the posixfile implementation a bit higher up in that file does.

In osutil.c, line 471 (in posixfile()), we already have:

	handle = CreateFile(name, access,
			    FILE_SHARE_READ | FILE_SHARE_WRITE |
			    FILE_SHARE_DELETE,
			    NULL,
			    creation,
			    FILE_ATTRIBUTE_NORMAL,
			    0);

That CreateFile call in posixfile() has been there since:

  changeset:   8330:7de68012f86e
  user:        Bryan O'Sullivan <bos at serpentine.com>
  date:        Fri May 08 15:52:26 2009 -0700
  summary:     Windows: improve performance via buffered I/O

which was released with 1.3 on 2009-07-01.

If there's any problem with using CreateFile in osutil.c then we already
have that problem since 1.3. posixfile is heavily used on Windows, for
example for 'hg update'.

For non-ascii characters in filenames, see the following manual test I did on
Windows 7 (in a new cmd.exe windows).

  $ chcp 1252
  Active code page: 1252

  $ hg -R C:\Users\adi\hgrepos\hg-crew parent
  changeset:   13289:6441aef24506
  branch:      stable
  tag:         nlinks
  tag:         qbase
  tag:         qtip
  tag:         tip
  parent:      13287:d0e0d3d43e14
  user:        Adrian Buehlmann <adrian at cadifra.com>
  date:        Sat Jan 22 19:21:35 2011 +0100
  summary:     implement nlinks() for _WIN32 in osutil.c (issue1922)


  $ set PYTHONPATH=C:\Users\adi\hgrepos\hg-crew

  $ echo bla > äöüéàèæ.txt

  $ dir /w
   Volume in drive C has no label.
   Volume Serial Number is F80E-0A52

   Directory of C:\Users\adi\hgrepos\tests\1

  [.]           [..]          äöüéàèæ.txt
                 1 File(s)              6 bytes
                 2 Dir(s)  437'756'362'752 bytes free

  $ python
  Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
  Type "help", "copyright", "credits" or "license" for more information.
  >>> from mercurial.windows import nlinks
  >>> nlinks('äöüéàèæ.txt')
  1
  >>> nlinks('bla')
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\Users\adi\hgrepos\hg-crew\mercurial\windows.py", line 27, in nlinks
      raise OSError(err.errno, '%s: %s' % (name, err.strerror))
  OSError: [Errno 2] bla: The system cannot find the file specified
  >>>


More information about the Mercurial-devel mailing list