summaryrefslogtreecommitdiff
path: root/mercurial/posix.py
diff options
context:
space:
mode:
Diffstat (limited to 'mercurial/posix.py')
-rw-r--r--mercurial/posix.py155
1 files changed, 6 insertions, 149 deletions
diff --git a/mercurial/posix.py b/mercurial/posix.py
index a97c076..367d7a4 100644
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -6,8 +6,7 @@
# GNU General Public License version 2 or any later version.
from i18n import _
-import encoding
-import os, sys, errno, stat, getpass, pwd, grp, tempfile, unicodedata
+import os, sys, errno, stat, getpass, pwd, grp, tempfile
posixfile = open
nulldev = '/dev/null'
@@ -85,21 +84,6 @@ def setflags(f, l, x):
# Turn off all +x bits
os.chmod(f, s & 0666)
-def copymode(src, dst, mode=None):
- '''Copy the file mode from the file at path src to dst.
- If src doesn't exist, we're using mode instead. If mode is None, we're
- using umask.'''
- try:
- st_mode = os.lstat(src).st_mode & 0777
- except OSError, inst:
- if inst.errno != errno.ENOENT:
- raise
- st_mode = mode
- if st_mode is None:
- st_mode = ~umask
- st_mode &= 0666
- os.chmod(dst, st_mode)
-
def checkexec(path):
"""
Check whether the given path is on a filesystem with UNIX-like exec flags
@@ -165,32 +149,8 @@ def samedevice(fpath1, fpath2):
st2 = os.lstat(fpath2)
return st1.st_dev == st2.st_dev
-# os.path.normcase is a no-op, which doesn't help us on non-native filesystems
-def normcase(path):
- return path.lower()
-
if sys.platform == 'darwin':
import fcntl # only needed on darwin, missing on jython
-
- def normcase(path):
- try:
- u = path.decode('utf-8')
- except UnicodeDecodeError:
- # percent-encode any characters that don't round-trip
- p2 = path.decode('utf-8', 'ignore').encode('utf-8')
- s = ""
- pos = 0
- for c in path:
- if p2[pos:pos + 1] == c:
- s += c
- pos += 1
- else:
- s += "%%%02X" % ord(c)
- u = s.decode('utf-8')
-
- # Decompose then lowercase (HFS+ technote specifies lower)
- return unicodedata.normalize('NFD', u).lower().encode('utf-8')
-
def realpath(path):
'''
Returns the true, canonical file system path equivalent to the given
@@ -224,63 +184,10 @@ if sys.platform == 'darwin':
return fcntl.fcntl(fd, F_GETPATH, '\0' * 1024).rstrip('\0')
finally:
os.close(fd)
-elif sys.version_info < (2, 4, 2, 'final'):
- # Workaround for http://bugs.python.org/issue1213894 (os.path.realpath
- # didn't resolve symlinks that were the first component of the path.)
- def realpath(path):
- if os.path.isabs(path):
- return os.path.realpath(path)
- else:
- return os.path.realpath('./' + path)
else:
# Fallback to the likely inadequate Python builtin function.
realpath = os.path.realpath
-if sys.platform == 'cygwin':
- # workaround for cygwin, in which mount point part of path is
- # treated as case sensitive, even though underlying NTFS is case
- # insensitive.
-
- # default mount points
- cygwinmountpoints = sorted([
- "/usr/bin",
- "/usr/lib",
- "/cygdrive",
- ], reverse=True)
-
- # use upper-ing as normcase as same as NTFS workaround
- def normcase(path):
- pathlen = len(path)
- if (pathlen == 0) or (path[0] != os.sep):
- # treat as relative
- return encoding.upper(path)
-
- # to preserve case of mountpoint part
- for mp in cygwinmountpoints:
- if not path.startswith(mp):
- continue
-
- mplen = len(mp)
- if mplen == pathlen: # mount point itself
- return mp
- if path[mplen] == os.sep:
- return mp + encoding.upper(path[mplen:])
-
- return encoding.upper(path)
-
- # Cygwin translates native ACLs to POSIX permissions,
- # but these translations are not supported by native
- # tools, so the exec bit tends to be set erroneously.
- # Therefore, disable executable bit access on Cygwin.
- def checkexec(path):
- return False
-
- # Similarly, Cygwin's symlink emulation is likely to create
- # problems when Mercurial is used from both Cygwin and native
- # Windows, with other native tools, or on shared volumes
- def checklink(path):
- return False
-
def shellquote(s):
if os.sys.platform == 'OpenVMS':
return '"%s"' % s
@@ -324,16 +231,13 @@ def findexe(command):
def findexisting(executable):
'Will return executable if existing file'
- if os.path.isfile(executable) and os.access(executable, os.X_OK):
+ if os.path.exists(executable):
return executable
return None
if os.sep in command:
return findexisting(command)
- if sys.platform == 'plan9':
- return findexisting(os.path.join('/bin', command))
-
for path in os.environ.get('PATH', '').split(os.pathsep):
executable = findexisting(os.path.join(path, command))
if executable is not None:
@@ -407,13 +311,10 @@ def termwidth():
continue
if not os.isatty(fd):
continue
- try:
- arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8)
- width = array.array('h', arri)[1]
- if width > 0:
- return width
- except AttributeError:
- pass
+ arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8)
+ width = array.array('h', arri)[1]
+ if width > 0:
+ return width
except ValueError:
pass
except IOError, e:
@@ -424,47 +325,3 @@ def termwidth():
except ImportError:
pass
return 80
-
-def makedir(path, notindexed):
- os.mkdir(path)
-
-def unlinkpath(f):
- """unlink and remove the directory if it is empty"""
- os.unlink(f)
- # try removing directories that might now be empty
- try:
- os.removedirs(os.path.dirname(f))
- except OSError:
- pass
-
-def lookupreg(key, name=None, scope=None):
- return None
-
-def hidewindow():
- """Hide current shell window.
-
- Used to hide the window opened when starting asynchronous
- child process under Windows, unneeded on other systems.
- """
- pass
-
-class cachestat(object):
- def __init__(self, path):
- self.stat = os.stat(path)
-
- def cacheable(self):
- return bool(self.stat.st_ino)
-
- __hash__ = object.__hash__
-
- def __eq__(self, other):
- try:
- return self.stat == other.stat
- except AttributeError:
- return False
-
- def __ne__(self, other):
- return not self == other
-
-def executablepath():
- return None # available on Windows only