Commit Graph

51 Commits

Author SHA1 Message Date
Robert Jones
6fa9874264 posix: check for executable bits on files identified by findexe function 2011-08-24 05:42:41 -04:00
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
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
Adrian Buehlmann
fefd0e5c0a util: move "default" hidewindow to posix.py
There is a hidewindow in win32.py, which we get via windows.py
2011-07-22 10:35:05 +02:00
Adrian Buehlmann
b3b6db23eb util: move "default" lookupreg to posix.py
There is a lookupreg in win32.py, which we get via windows.py
2011-07-22 10:31:56 +02:00
Adrian Buehlmann
f5f99a1f05 util: move "default" unlinkpath to posix.py
we have a unlinkpath in windows.py
2011-07-22 09:55:46 +02:00
Adrian Buehlmann
0da6a5ee7a util: move "default" makedir to posix.py
makedir is already defined in win32.py, which gets imported into util.py
via windows.py if we are running on Windows
2011-07-22 09:53:15 +02:00
Adrian Buehlmann
b0bff1062c rename util.is_exec to isexec 2011-05-08 20:45:47 +02:00
Adrian Buehlmann
c241b3cee1 posix: delete unused expand_glob 2011-05-08 20:42:28 +02:00
Adrian Buehlmann
4163cf2e6f rename util.find_exe to findexe 2011-05-08 20:35:46 +02:00
Adrian Buehlmann
b79bd6d178 rename util.set_signal_handler to setsignalhandler 2011-05-06 15:41:04 +02:00
Adrian Buehlmann
5573dff691 rename util.os_link to oslink 2011-05-06 15:34:34 +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
jfh
60fbf29159 util.termwidth: never return 0 for terminal width
Catch a case where the termwidth was being reported as 0 when I was connecting
with TLMTask instead of NSTask in OSX. This caused the progress extension to
print no progress. The termwidth should never return 0 so in case we would
return 0, simply fall back to the default termwidth below which is 80.
2011-04-18 02:42:52 +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
9b801e586d path_auditor: check filenames for basic platform validity (issue2755)
Example (on Windows):

  $ hg parents
  $ hg manifest tip
  con.xml
  $ hg update
  abort: filename contains 'con', which is reserved on Windows: con.xml

Before this patch, update produced (as explained in issue2755):

  $ hg update
  abort: No usable temporary filename found

I've added the new function checkwinfilename to util.py and not to windows.py,
so that we can later call it when running on posix platforms too, for when we
decide to implement a (configurable) warning message on 'hg add'.

As per this patch, checkwinfilename is currently only used when running
on Windwows.

path_auditor calls checkosfilename, which is a NOP on posix and an alias for
checkwinfilename on Windows.
2011-04-06 18:09:43 +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
Dan Villiom Podlaski Christiansen
ec590d5cd4 explicitly close files
Add missing calls to close() to many places where files are
opened. Relying on reference counting to catch them soon-ish is not
portable and fails in environments with a proper GC, such as PyPy.
2010-12-24 15:23:01 +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
Dan Villiom Podlaski Christiansen
d256bab10f posix: remove is-comparison between integers
Comparing integers by identity relies on a CPython implementation
detail of caching integers between -5 and 256.[1]

[1] <http://docs.python.org/c-api/int.html#PyInt_FromLong>
2010-11-16 21:35:58 +01:00
Augie Fackler
42c8b2cf07 termwidth: move to ui.ui from util 2010-10-10 10:06:36 -05:00
Patrick Mezard
842d65c40f acl: grp module is not available on windows 2010-05-10 21:09:48 +02:00
Patrick Mezard
d05da88022 Merge with crew-stable 2010-04-26 22:42:46 +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
Ronny Pfannschmidt
66fa69cb0e posix: move a global fcntl import to keep it from breaking jython
Only needed on darwin, anyway.
2010-03-23 11:37:01 +01: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
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
Adrian Buehlmann
db3cee7306 util: move rename into posix.py and windows.py 2009-10-07 20:32:07 +02:00
Mads Kiilerich
097282895a util.system: Use subprocess instead of os.system
subprocess allows the environment and working directory to be specified
directly, so the hacks for making temporary changes while forking is no longer
necessary.

This also fixes failures on solaris where the temporary changes can't be undone
because there is no unsetenv.
2009-09-20 22:19:18 +02: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
Alejandro Santos
77d606ac51 compat: use open() instead of file() everywhere 2009-07-05 11:01:30 +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
Patrick Mezard
e8790c2140 serve: add and use portable spawnvp replacement
There is no standard python command to really detach a process under Windows.
Instead we use the low level API wrapped by subprocess module with all
necessary options to avoid any kind of context inheritance. Unfortunately, this
version still opens a new window for the child process.

The following have been tried:
- os.spawnv(os.P_NOWAIT): works but the child process is killed when parent
  console terminates.
- os.spawnv(os.P_DETACH): works on python25, hang on python26 when writing to
  the hgweb output socket.
- subprocess.CreateProcess() hack without shell mode: similar to
  os.spawnv(os.P_DETACH).

Fix 1/3 for issue421
2009-04-10 21:20:25 +02:00
Simon Heimberg
09ac1e6c92 separate import lines from mercurial and general python modules 2009-04-28 17:40:46 +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
Peter Arrenbrecht
7b457d8a6a whitespace cleanup 2009-04-27 09:12:07 +02:00
Matt Mackall
bcbc752a6f posix: kill some trailing newlines 2009-04-03 12:37:07 -05:00
Rocco Rutte
895d037e99 Add missing imports for posix.py for OS X
These don't seem to do harm on Linux.
2009-03-27 17:56:18 +01:00