Commit Graph

43 Commits

Author SHA1 Message Date
Matt Mackall
ce9126c527 win32: quietly ignore missing CreateHardLinkA for Wine 2011-09-13 17:01:07 -05:00
Adrian Buehlmann
5884f8cd09 win32.py: add argtypes and restype
This is a feature of ctypes. Without these, pypy complains with

  RuntimeWarning: C function without declared arguments called
  RuntimeWarning: C function without declared return type called

As a side effect of specifying restypes, the return value of e.g. CreateFileA
is now implicitly converted to an instance of _HANDLE, so we also need to
change the definition

  _INVALID_HANDLE_VALUE = -1

to

  _INVALID_HANDLE_VALUE = _HANDLE(-1).value

Otherwise, tests for equality to _INVALID_HANDLE_VALUE in code like

  def _getfileinfo(name):
      fh = _kernel32.CreateFileA(name, 0,
              _FILE_SHARE_READ | _FILE_SHARE_WRITE | _FILE_SHARE_DELETE,
              None, _OPEN_EXISTING, 0, None)
      if fh == _INVALID_HANDLE_VALUE:
          _raiseoserror(name)

would now fail to detect an invalid handle, which in turn would lead to
exceptions raised with wrong errno values, like e.g.

  >>> nlinks('missing.txt')
  Traceback (most recent call last):
  ...
  OSError: [Errno 9] missing.txt: The handle is invalid.

instead of the correct (as per this patch and before it)

  >>> nlinks('missing.txt')
  Traceback (most recent call last):
  ...
  OSError: [Errno 2] missing.txt: The system cannot find the file specified.
2011-05-15 21:33:51 +02:00
Adrian Buehlmann
1301f80255 win32.py: more explicit definition of _STD_ERROR_HANDLE 2011-05-15 21:27:59 +02:00
Adrian Buehlmann
b79bd6d178 rename util.set_signal_handler to setsignalhandler 2011-05-06 15:41:04 +02:00
Adrian Buehlmann
b84ce08e82 rename util.executable_path to executablepath 2011-05-06 15:36:05 +02:00
Adrian Buehlmann
5573dff691 rename util.os_link to oslink 2011-05-06 15:34:34 +02:00
Adrian Buehlmann
554b565228 rename util.lookup_reg to lookupreg 2011-05-06 15:16:22 +02:00
Matt Mackall
c0ef80263c win32: Wine doesn't know about hardlinks 2011-04-21 15:08:48 -05:00
Adrian Buehlmann
92624f7391 set NOT_CONTENT_INDEXED on .hg dir (issue2694)
when running on Windows
2011-03-28 15:54:22 +02:00
Adrian Buehlmann
278d76a89c win32: remove READONLY attribute on unlink 2011-03-27 01:47:58 +01:00
Adrian Buehlmann
e1730e6f6b windows: move unlink to win32.py
no code change
2011-03-27 01:17:48 +01:00
Adrian Buehlmann
5a005c60c3 eliminate win32.user_rcpath_win32() 2011-02-14 11:13:05 +01:00
Adrian Buehlmann
2f13e93b12 win32: move system_rcpath_win32() to windows.py
no code change in system_rcpath_win32

This breaks the dependency from the win32 module on osutil
2011-02-14 11:12:35 +01:00
Adrian Buehlmann
a264a23ffa win32: new function executable_path 2011-02-14 11:12:31 +01:00
Adrian Buehlmann
77ab03f101 port win32.py to using the Python ctypes library
The pywin32 package is no longer needed.

ctypes is now required for running Mercurial on Windows.

ctypes is included in Python since version 2.5. For Python 2.4, ctypes is
available as an extra installer package for Windows.

Moved spawndetached() from windows.py to win32.py and fixed it, using
ctypes as well. spawndetached was defunct with Python 2.6.6 because Python
removed their undocumented subprocess.CreateProcess. This fixes
'hg serve -d' on Windows.
2011-02-14 11:12:26 +01:00
Adrian Buehlmann
9669b3b2bc win32: optimize parameters for the CreateFile call in _getfileinfo
Set dwDesiredAccess to 0 instead of GENERIC_READ.
Zero is  enough for querying the file metadata. We don't even need to
access the -contents- of the file.

Set dwShareMode to FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
instead of the overly restrictive FILE_SHARE_READ.
There is no need to cause write or delete accesses by other processes to
fail while we are querying file metadata.

See http://msdn.microsoft.com/en-us/library/aa363858(v=vs.85).aspx
2011-02-14 11:12:22 +01:00
Steve Borho
f5cf898232 win32: win32console.GetStdHandle() can return None
When the Mercurial Python libraries are used within a Windows application with
no console, there is no stderr file handle.
2011-01-21 14:42:15 -06:00
Yuya Nishihara
675210cf34 win32: remove try-catch block of GetModuleFileNameEx (issue2480)
According to the API document, GetModuleFileName is the preferred way to
retrieve the filename of the current process. So we shouldn't try
GetModuleFileName'Ex' first.

Previously system_rcpath_win32() happened to return unicode paths due to
GetModuleFileNameEx (issue2480). This problem is fixed as GetModuleFileName
never return unicode.
2010-11-11 01:12:51 +09:00
Adrian Buehlmann
b1824b07a4 opener: check hardlink count reporting (issue1866)
The Linux CIFS kernel driver (even in 2.6.36) suffers from a hardlink
count blindness bug (lstat() returning 1 in st_nlink when it is expected
to return >1), which causes repository corruption if Mercurial running
on Linux pushes or commits to a hardlinked repository stored on a Windows
share, if that share is mounted using the CIFS driver.

This patch works around issue1866 and improves the workaround done in
65e082ae3076 to fix issue761, by teaching the opener to lazily execute a
runtime check (new function checknlink) to see if the hardlink count
reported by nlinks() can be trusted.

Since nlinks() is also known to return varying count values (1 or >1)
depending on whether the file is open or not and depending on what client
and server software combination is being used for accessing and serving
the Windows share, we deliberately open the file before calling nlinks() in
order to have a stable precondition. Trying to depend on the precondition
"file closed" would be fragile, as the file could have been opened very
easily somewhere else in the program.
2010-11-07 18:21:29 +01:00
Augie Fackler
42c8b2cf07 termwidth: move to ui.ui from util 2010-10-10 10:06:36 -05:00
Matt Mackall
51b3b09c8f backout most of 26e0b9a8ce0d 2010-09-24 12:46:54 -05:00
Brodie Rao
7362459729 cleanup: use x in (a, b) instead of x == a or x == b 2010-09-23 00:02:31 -05:00
Patrick Mezard
efbdac1e61 win32: remove useless lstat() fallback in nlinks()
The fallback was introduced by 33415b0b4e64 at the same time than
nlinks(). Apparently it only handles the case where target path
does not exist. Just raise IOError directly.
2010-08-19 22:51:09 +02:00
Patrick Mezard
5e126e9b42 win32: correctly break hardlinks on network drives (issue761)
win32.nlinks() was often returning 1 instead of the correct
hardlinks count when reading from network drives. This made
commit or push to a repository on a network share to fail
breaking the hardlinks in the datastore, possibly causing
integrity errors in repositories linked locally on the remote
side.

Here is what the MSDN says about GetFileInformationByHandle():

  Depending on the underlying network features of the operating
  system and the type of server connected to, the
  GetFileInformationByHandle function may fail, return partial
  information, or full information for the given file.

In practice, we never got the correct hardlinks count when
reading from and to many combinations of Window XP, 2003, Vista
and 7, via network drives or RDP shares. It always returned 1
instead. The only setup returning an accurate links count was a
samba on Debian.

To avoid this, Mercurial now breaks the hardlinks unconditionally
when writing to a network drive.
2010-08-19 22:51:09 +02:00
Dirkjan Ochtman
cb25b6f79d cleanups: unused variables 2010-06-08 09:30:33 +02:00
Patrick Mezard
88569d9b27 win32: detect console width on Windows
Original version by anatoly techtonik <techtonik@gmail.com>
Following advices from similar bzr code.
2010-04-25 18:27:12 +02:00
Steve Borho
9a5cb3aaab win32: allow hgrc.d on Windows 2010-02-07 05:34:22 -06:00
Matt Mackall
cd3ef170f7 Merge with stable 2010-01-19 22:45:09 -06:00
Matt Mackall
595d66f424 Update license to GPLv2+ 2010-01-19 22:20:08 -06:00
Patrick Mezard
052695b2e4 cmdutil: hide child window created by win32 spawndetached()
Hiding the child process window is not strictly necessary but it avoids opening
an empty shell window when running hg serve as well as a task in the task bar.
The window is hidden after the process is already started causing a single
flicker.
2010-01-10 18:13:34 +01:00
Patrick Mezard
be67c8a241 win32: close file when leaving _getfileinfo() 2010-01-08 23:15:22 +01:00
Siddharth Agarwal
eab3968819 Add support for relinking on Windows.
Test and minor code change by Patrick Mézard <pmezard@gmail.com>
2010-01-08 18:48:39 +05:30
Martin Geisler
ae0794fd45 coding style: use a space after comma
I left a cases like 'lambda x,y:' alone -- the lack of a space does
not bother me as much when the variables are single letters.
2009-07-22 23:12:54 +02:00
Henrik Stuart
97f9be9c1f windows: fix use of undefined exception (issue1707)
This fixes the implied reliance on pywin32 and the win32 module. This
also fixes a regression in fe7c89838a64 that made Mercurial unusable
without pywin32.
2009-06-25 22:43:58 +02:00
Martin Geisler
58e8fb6277 removed unused imports 2009-05-30 23:20:30 +02:00
Sune Foldager
adc90b2605 posixfile: remove posixfile_nt and fix import bug in windows.py
The posixfile_nt class has been superseded by posixfile in osutils.c,
which works on Windows NT and above. All other systems get the regular
python file class which is assigned to posixfile in posix.py (for POSIX)
and in the pure python version of osutils.py (for Win 9x or Windows NT
in pure mode).
2009-05-13 21:36:16 +02:00
Bryan O'Sullivan
25eaff219f win32: clarify comment regarding use of fdopen 2009-03-26 13:14:35 -07:00
Bryan O'Sullivan
3b57c5ca0f win32: allow catching of both pywintypes.error and WindowsError 2009-03-26 13:13:48 -07:00
Martin Geisler
2c8901a1b9 turn some comments back into module docstrings 2009-04-26 01:24:49 +02:00
Martin Geisler
8e4bc1e9ad put license and copyright info into comment blocks 2009-04-26 01:13:08 +02:00
Martin Geisler
750183bdad updated license to be explicit about GPL version 2 2009-04-26 01:08:54 +02:00
Matt Mackall
642f4d7151 move encoding bits from util to encoding
In addition to cleaning up util, this gets rid of some circular dependencies.
2009-04-03 14:51:48 -05:00
Matt Mackall
0952760f82 util: split out posix, windows, and win32 modules 2009-03-26 13:54:44 -05:00