Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 5159:d84329a11fdd
Make a few portability improvements to path auditing code.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Fri, 10 Aug 2007 10:51:47 -0700 |
parents | d316124ebbea |
children | 9374373fb727 |
comparison
equal
deleted
inserted
replaced
5158:d316124ebbea | 5159:d84329a11fdd |
---|---|
696 self.root = root | 696 self.root = root |
697 | 697 |
698 def __call__(self, path): | 698 def __call__(self, path): |
699 if path in self.audited: | 699 if path in self.audited: |
700 return | 700 return |
701 parts = os.path.normcase(path).split(os.sep) | 701 normpath = os.path.normcase(path) |
702 parts = normpath.split(os.sep) | |
702 if (os.path.splitdrive(path)[0] or parts[0] in ('.hg', '') | 703 if (os.path.splitdrive(path)[0] or parts[0] in ('.hg', '') |
703 or os.pardir in parts): | 704 or os.pardir in parts): |
704 raise Abort(_("path contains illegal component: %s") % path) | 705 raise Abort(_("path contains illegal component: %s") % path) |
705 def check(prefix): | 706 def check(prefix): |
706 curpath = os.path.join(self.root, prefix) | 707 curpath = os.path.join(self.root, prefix) |
711 raise | 712 raise |
712 else: | 713 else: |
713 if stat.S_ISLNK(st.st_mode): | 714 if stat.S_ISLNK(st.st_mode): |
714 raise Abort(_('path %r traverses symbolic link %r') % | 715 raise Abort(_('path %r traverses symbolic link %r') % |
715 (path, prefix)) | 716 (path, prefix)) |
716 if os.path.exists(os.path.join(curpath, '.hg')): | 717 elif (stat.S_ISDIR(st.st_mode) and |
718 os.path.isdir(os.path.join(curpath, '.hg'))): | |
717 raise Abort(_('path %r is inside repo %r') % | 719 raise Abort(_('path %r is inside repo %r') % |
718 (path, prefix)) | 720 (path, prefix)) |
719 self.audited[prefix] = True | 721 self.audited[prefix] = True |
720 for c in strutil.rfindall(path, os.sep): | 722 for c in strutil.rfindall(normpath, os.sep): |
721 check(path[:c]) | 723 check(normpath[:c]) |
722 self.audited[path] = True | 724 self.audited[path] = True |
723 | 725 |
724 def _makelock_file(info, pathname): | 726 def _makelock_file(info, pathname): |
725 ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL) | 727 ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL) |
726 os.write(ld, info) | 728 os.write(ld, info) |