Commit Graph

66 Commits

Author SHA1 Message Date
Adrian Buehlmann
50665a9994 util: move copymode into posix.py and windows.py
reducing it to a NOP on Windows.

This eliminates a pointless stat call on Windows and reduces the risk of
interferring with other processes (e.g. AV-scanners, file change watchers).

See also http://mercurial.selenic.com/wiki/UnlinkingFilesOnWindows, item 2d
2011-08-02 13:18:56 +02:00
Adrian Buehlmann
b58d26815b windows: eliminate win32 wildcard import 2011-07-29 00:39:27 +02:00
Augie Fackler
d65f3985a6 windows: use getattr instead of hasattr 2011-07-25 16:04:44 -05:00
Idan Kamara
09359f3d7d posix, windows: introduce cachestat
This class contains a stat result, and possibly other file info to reliably
determine between two points in time whether a file has changed.

Uniquely identifying a file gives us that reliability because we either
atomic rename or append. So one of two will happen: the file 'id' will change,
or the size of the file will change.

posix implements it simply by calling os.stat() and checking if the result
has st_ino.

For now on Windows we always assume the path is uncacheable. This can be
improved on NTFS due to file IDs: http://msdn.microsoft.com/en-us/library/aa363788(v=vs.85).aspx

So we need to find out if a file path is on an NTFS drive, for that we have:

- GetVolumeInformation, which unfortunately only works with a root path (but is available on XP)
- GetVolumeInformationByHandleW, works on a full file path but requires Vista or higher
2011-07-25 15:03:02 +03:00
Adrian Buehlmann
f1218befa0 util: eliminate wildcard imports 2011-07-23 12:29:52 +02:00
Idan Kamara
361e7cfb4a win32: assign winstdout to sys.__stdout__ as well (issue2888)
On Windows sys.stdout was being replaced with winstdout, which caused
util.system() to redirect its output (due to 388eabdda556). That causes
interactive tools (such as vim) to stop working.
2011-07-16 15:24:28 +03:00
Adrian Buehlmann
4163cf2e6f rename util.find_exe to findexe 2011-05-08 20:35:46 +02:00
Adrian Buehlmann
e94d06bb79 rename explain_exit to explainexit 2011-05-06 15:31:09 +02:00
Adrian Buehlmann
0e6715fa28 rename util.set_binary to setbinary 2011-05-06 15:25:35 +02:00
Adrian Buehlmann
c415440828 rename util.set_flags to setflags 2011-05-06 15:22:31 +02:00
Adrian Buehlmann
eb8027ea31 rename util.parse_patch_output to parsepatchoutput 2011-05-06 15:19:48 +02:00
Alexander Solovyov
0eb3836642 remove unused imports and variables 2011-04-30 13:59:14 +02:00
Idan Kamara
762d333ae9 eliminate various naked except clauses 2011-04-23 00:51:25 +03:00
Adrian Buehlmann
a928db8b4e move system_rcpath and user_rcpath to scmutil 2011-04-21 21:16:54 +02:00
Adrian Buehlmann
34d2bab4e0 util: move checklink() to posix.py and return False on Windows
Python added support for Windows 6.0 (Vista) symbolic links in 3.2 [1], but
even these symbolic links aren't what we can expect from a canonical
symbolic link, since creation requires SeCreateSymbolicLinkPrivilege,
which typically only admins have.

So we can safely assume that we don't have symbolic links on Windows.

[1] http://docs.python.org/py3k/library/os.html#os.symlink
2011-04-05 11:55:52 +02:00
Adrian Buehlmann
b82d6c0417 util: move checkexec() to posix.py and return False on Windows 2011-04-04 11:41:54 +02:00
Adrian Buehlmann
aeda606d1d windows: use win32.unlink in unlinkpath()
os.unlink fails to remove files with READONLY attribute
2011-03-27 12:22:07 +02: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
c0a4dc75ea windows: eliminate system_rcpath_win32() 2011-02-14 11:12:57 +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
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
c83b01e7a1 reintroduces util.unlink, for POSIX and Windows.
windows: factor it out of rename
posix: add alias 'unlink' for os.unlink

Note that this new unlink function now has different semantics than the
unlink() we had before changeset 5c424b3de62c ("rename util.unlink to
unlinkpath").
2011-01-11 14:10:16 +01:00
Adrian Buehlmann
f90344c20e windows.rename: check OSError for EEXIST
For example, if src has been opened with Python's open(), os.rename will
raise EACCES. Continuing in that case is pointless.
2011-01-11 14:10:16 +01:00
Adrian Buehlmann
721e368ac1 rename util.unlink to unlinkpath 2011-01-02 19:34:41 +01:00
Adrian Buehlmann
bfc33d780a windows.rename: eliminate temp name race (issue2571)
On Windows, os.rename reliably raises OSError with errno.EEXIST if the
destination already exists (even on shares served by Samba).

Windows does *not* silently overwrite the destination of a rename.

So there is no need to first call os.path.exists on the chosen temp path.

Trusting os.path.exists is actually harmful, since using it enables the
following racy sequence of actions:

 1) os.path.exists(temp) returns False
 2) some evil other process creates a file with name temp
 3) os.rename(dst, temp) now fails because temp has been taken

Not using os.path.exists and directly trying os.rename(dst, temp)
eliminates this race.
2010-12-27 01:12:31 +01:00
Steve Borho
8562094eb1 util: concentrate quoting knowledge to windows.py quotecommand()
This fixes all callers of util.quotecommand() and place special knowledge
of the bugfix in 2.7.1 in a single platform specific place.
2010-12-22 13:25:00 -06:00
Augie Fackler
42c8b2cf07 termwidth: move to ui.ui from util 2010-10-10 10:06:36 -05:00
Brodie Rao
0f9d940cb9 cleanup: remove unused variables 2010-08-27 13:32:40 -04:00
Patrick Mezard
842d65c40f acl: grp module is not available on windows 2010-05-10 21:09:48 +02:00
Patrick Mezard
b7c02777e0 util: fix default termwidth() under Windows
sys.stdout.write('-'*80 + '\n')

or

  sys.stdout.write('-'*80 + '\r')

do not work on Windows as they do on unix. On a 80 columns Windows console, the
extra CR or LF are interpreted as if belonging to the next line, so the first
command displays 2 lines (only one on unix) and the second one leave the line
visible and move back to the following line. To avoid this, we sacrifice one
column under Windows.
2010-04-26 22:30:40 +02:00
Benoit Boissinot
328394047f fix coding style (reported by pylint) 2010-02-08 15:36:34 +01:00
Matt Mackall
8d99be19f0 many, many trivial check-code fixups 2010-01-25 00:05:27 -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
48eee05938 Find right hg command for detached process
On Windows, Mercurial can be run from the python script of from a frozen
executable. In the first case, we have to call the python interpreter since the
script is not executable. Frozen executable can be called directly.

Fix 3/3 for issue421
2010-01-06 21:11:58 +01:00
Matt Mackall
b6547e5312 Merge with stable 2009-10-11 13:54:19 -05:00
Patrick Mezard
6815e3dc8d windows: fix unlink() not dropping empty tree (issue1861) 2009-10-08 23:32:36 +02:00
Adrian Buehlmann
db3cee7306 util: move rename into posix.py and windows.py 2009-10-07 20:32:07 +02:00
Steve Borho
9a9a300480 Merge with crew-stable 2009-09-15 11:18:12 -05:00
Steve Borho
68d79882b6 windows: provide filename in IOError exceptions
This brings the Windows posixfile errors in line with the errors
on other platforms.
2009-09-14 19:53:43 -05:00
James Abbatiello
493895e163 Fix test-demandimport and test-trusted under Windows
The Windows-only wrapper around stdout is causing both of these tests to fail.
test-demandimport fails because it tries to print repr(sys.stdout).  Use
stderr instead since that is not wrapped.

test-trusted fails because the wrapper doesn't handle softspace and an
unexpected extra space gets printed.
2009-07-14 22:38:12 -04:00
Shun-ichi GOTO
e9a5aa00b3 Use os.path.split() for MBCS with win32mbcs extension. 2009-07-09 21:39:19 +09:00
Dan Villiom Podlaski Christiansen
5cd95d0ef8 util: add realpath() for getting the 'true' path.
The function is implemented for Mac OS X using the F_GETPATH fcntl,
and a basic implementation for Windows is provided as well. On other
POSIX systems, vanilla os.path.realpath() is used.
2009-07-26 17:25:08 +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
Dirkjan Ochtman
115b52ec56 windows: import WinIOError from win32 module (issue1707)
Quick fix pending further refactoring of windows error handling.
2009-06-24 12:03:53 +02:00
Benoit Boissinot
125a85ec87 use new style classes 2009-06-10 15:10:21 +02:00
timeless
fb33de67af Generally replace "file name" with "filename" in help and comments. 2009-06-09 09:25:17 -04:00
Martin Geisler
cac71647b1 posix: do not use fstat in isowner
The fstat function was undefined, but never used since a stat object
was always passed in the optional st argument. Passing st is now
mandatory.

This bug crept in when util was split up into posix and windows
modules. The fstat function is still defined in util, but importing it
into posix would create an import cycle which seems unnecessary.
2009-05-30 23:42:35 +02:00
Matt Mackall
a30eb02911 cmdutils: Take over glob expansion duties from util 2009-05-24 16:38:29 -05:00