Ejemplo n.º 1
0
    def __call__(self, path):
        '''Check the relative path.
        path may contain a pattern (e.g. foodir/**.txt)'''

        path = util.localpath(path)
        normpath = self.normcase(path)
        if normpath in self.audited:
            return
        # AIX ignores "/" at end of path, others raise EISDIR.
        if util.endswithsep(path):
            raise util.Abort(_("path ends in directory separator: %s") % path)
        parts = util.splitpath(path)
        if (os.path.splitdrive(path)[0]
                or parts[0].lower() in ('.hg', '.hg.', '')
                or os.pardir in parts):
            raise util.Abort(_("path contains illegal component: %s") % path)
        if '.hg' in path.lower():
            lparts = [p.lower() for p in parts]
            for p in '.hg', '.hg.':
                if p in lparts[1:]:
                    pos = lparts.index(p)
                    base = os.path.join(*parts[:pos])
                    raise util.Abort(
                        _("path '%s' is inside nested repo %r") % (path, base))

        normparts = util.splitpath(normpath)
        assert len(parts) == len(normparts)

        parts.pop()
        normparts.pop()
        prefixes = []
        while parts:
            prefix = os.sep.join(parts)
            normprefix = os.sep.join(normparts)
            if normprefix in self.auditeddir:
                break
            curpath = os.path.join(self.root, prefix)
            try:
                st = os.lstat(curpath)
            except OSError, err:
                # EINVAL can be raised as invalid path syntax under win32.
                # They must be ignored for patterns can be checked too.
                if err.errno not in (errno.ENOENT, errno.ENOTDIR,
                                     errno.EINVAL):
                    raise
            else:
                if stat.S_ISLNK(st.st_mode):
                    raise util.Abort(
                        _('path %r traverses symbolic link %r') %
                        (path, prefix))
                elif (stat.S_ISDIR(st.st_mode)
                      and os.path.isdir(os.path.join(curpath, '.hg'))):
                    if not self.callback or not self.callback(curpath):
                        raise util.Abort(
                            _("path '%s' is inside nested "
                              "repo %r") % (path, prefix))
            prefixes.append(normprefix)
            parts.pop()
            normparts.pop()
Ejemplo n.º 2
0
    def __call__(self, path):
        '''Check the relative path.
        path may contain a pattern (e.g. foodir/**.txt)'''

        path = util.localpath(path)
        normpath = self.normcase(path)
        if normpath in self.audited:
            return
        # AIX ignores "/" at end of path, others raise EISDIR.
        if util.endswithsep(path):
            raise util.Abort(_("path ends in directory separator: %s") % path)
        parts = util.splitpath(path)
        if (os.path.splitdrive(path)[0]
            or parts[0].lower() in ('.hg', '.hg.', '')
            or os.pardir in parts):
            raise util.Abort(_("path contains illegal component: %s") % path)
        if '.hg' in path.lower():
            lparts = [p.lower() for p in parts]
            for p in '.hg', '.hg.':
                if p in lparts[1:]:
                    pos = lparts.index(p)
                    base = os.path.join(*parts[:pos])
                    raise util.Abort(_("path '%s' is inside nested repo %r")
                                     % (path, base))

        normparts = util.splitpath(normpath)
        assert len(parts) == len(normparts)

        parts.pop()
        normparts.pop()
        prefixes = []
        while parts:
            prefix = os.sep.join(parts)
            normprefix = os.sep.join(normparts)
            if normprefix in self.auditeddir:
                break
            curpath = os.path.join(self.root, prefix)
            try:
                st = os.lstat(curpath)
            except OSError, err:
                # EINVAL can be raised as invalid path syntax under win32.
                # They must be ignored for patterns can be checked too.
                if err.errno not in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL):
                    raise
            else:
                if stat.S_ISLNK(st.st_mode):
                    raise util.Abort(
                        _('path %r traverses symbolic link %r')
                        % (path, prefix))
                elif (stat.S_ISDIR(st.st_mode) and
                      os.path.isdir(os.path.join(curpath, '.hg'))):
                    if not self.callback or not self.callback(curpath):
                        raise util.Abort(_("path '%s' is inside nested "
                                           "repo %r")
                                         % (path, prefix))
            prefixes.append(normprefix)
            parts.pop()
            normparts.pop()
Ejemplo n.º 3
0
    def __call__(self, path):
        """Check the relative path.
        path may contain a pattern (e.g. foodir/**.txt)"""

        path = util.localpath(path)
        normpath = self.normcase(path)
        if normpath in self.audited:
            return
        # AIX ignores "/" at end of path, others raise EISDIR.
        if util.endswithsep(path):
            raise util.Abort(_("path ends in directory separator: %s") % path)
        parts = util.splitpath(path)
        if os.path.splitdrive(path)[0] or _lowerclean(parts[0]) in (".hg", ".hg.", "") or os.pardir in parts:
            raise util.Abort(_("path contains illegal component: %s") % path)
        # Windows shortname aliases
        for p in parts:
            if "~" in p:
                first, last = p.split("~", 1)
                if last.isdigit() and first.upper() in ["HG", "HG8B6C"]:
                    raise util.Abort(_("path contains illegal component: %s") % path)
        if ".hg" in _lowerclean(path):
            lparts = [_lowerclean(p.lower()) for p in parts]
            for p in ".hg", ".hg.":
                if p in lparts[1:]:
                    pos = lparts.index(p)
                    base = os.path.join(*parts[:pos])
                    raise util.Abort(_("path '%s' is inside nested repo %r") % (path, base))

        normparts = util.splitpath(normpath)
        assert len(parts) == len(normparts)

        parts.pop()
        normparts.pop()
        prefixes = []
        while parts:
            prefix = os.sep.join(parts)
            normprefix = os.sep.join(normparts)
            if normprefix in self.auditeddir:
                break
            curpath = os.path.join(self.root, prefix)
            try:
                st = os.lstat(curpath)
            except OSError, err:
                # EINVAL can be raised as invalid path syntax under win32.
                # They must be ignored for patterns can be checked too.
                if err.errno not in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL):
                    raise
            else:
                if stat.S_ISLNK(st.st_mode):
                    raise util.Abort(_("path %r traverses symbolic link %r") % (path, prefix))
                elif stat.S_ISDIR(st.st_mode) and os.path.isdir(os.path.join(curpath, ".hg")):
                    if not self.callback or not self.callback(curpath):
                        raise util.Abort(_("path '%s' is inside nested " "repo %r") % (path, prefix))
            prefixes.append(normprefix)
            parts.pop()
            normparts.pop()
Ejemplo n.º 4
0
def parse_path(file_path):
    """Return a dict with entries for 'julian' dir and 'file' name"""
    julian_re = re.compile(r'^20\d{2}_\d{1,3}$')
    d = {"julian": None, "file": None}
    parts = util.splitpath(file_path)
    if len(parts) == 1:
        d["file"] = parts[0]
    elif len(parts) > 1:
        d["file"] = parts[-1]
        if julian_re.match(parts[-2]):
            d["julian"] = parts[-2]
    return d
Ejemplo n.º 5
0
def parse_path(file_path):
    """Return a dict with entries for 'julian' dir and 'file' name"""
    julian_re = re.compile(r'^20\d{2}_\d{1,3}$')
    d = { "julian": None, "file": None }
    parts = util.splitpath(file_path)
    if len(parts) == 1:
        d["file"] = parts[0]
    elif len(parts) > 1:
        d["file"] = parts[-1]
        if julian_re.match(parts[-2]):
            d["julian"] = parts[-2]
    return d
Ejemplo n.º 6
0
    def build_tree(self, data, folder):
        self.ui.file_treeWidget.clear()

        def insert(l: dict, p: list):
            if p[1:] == p[:-1]:
                return
            for i in p:
                if i not in l:
                    l.update({i: {}})
                x = OrderedDict(sorted(l.get(i).items()))
                l[i] = x
                l = x

        def inner_build(l, parent=None):
            if not l:
                return
            for i in l.keys():
                if not parent:
                    self.root = QTreeWidgetItem(self.ui.file_treeWidget)
                    p = self.root
                else:
                    child1 = QTreeWidgetItem(parent)
                    p = child1
                p.setText(0, i)
                if l.get(i):
                    inner_build(l.get(i), p)
            self.ui.file_treeWidget.addTopLevelItem(self.root)
            self.ui.file_treeWidget.setColumnWidth(0, 160)
            self.ui.file_treeWidget.expandAll()

        path_list = util.splitpath(folder + self.linker.separator)
        insert(self.my, path_list)
        for i in data:
            if i.is_dir is "T":
                if not "." in i.name or not "." in i.name:
                    folder = i.name.replace("//", "/")
                    insert(self.my,
                           util.splitpath(folder + self.linker.separator))
        inner_build(self.my, None)
Ejemplo n.º 7
0
    def __call__(self, path):
        '''Check the relative path.
        path may contain a pattern (e.g. foodir/**.txt)'''

        path = util.localpath(path)
        normpath = self.normcase(path)
        if normpath in self.audited:
            return
        # AIX ignores "/" at end of path, others raise EISDIR.
        if util.endswithsep(path):
            raise util.Abort(_("path ends in directory separator: %s") % path)
        parts = util.splitpath(path)
        if (os.path.splitdrive(path)[0]
            or _lowerclean(parts[0]) in ('.hg', '.hg.', '')
            or os.pardir in parts):
            raise util.Abort(_("path contains illegal component: %s") % path)
        # Windows shortname aliases
        for p in parts:
            if "~" in p:
                first, last = p.split("~", 1)
                if last.isdigit() and first.upper() in ["HG", "HG8B6C"]:
                    raise util.Abort(_("path contains illegal component: %s")
                                     % path)
        if '.hg' in _lowerclean(path):
            lparts = [_lowerclean(p.lower()) for p in parts]
            for p in '.hg', '.hg.':
                if p in lparts[1:]:
                    pos = lparts.index(p)
                    base = os.path.join(*parts[:pos])
                    raise util.Abort(_("path '%s' is inside nested repo %r")
                                     % (path, base))

        normparts = util.splitpath(normpath)
        assert len(parts) == len(normparts)

        parts.pop()
        normparts.pop()
        prefixes = []
        while parts:
            prefix = os.sep.join(parts)
            normprefix = os.sep.join(normparts)
            if normprefix in self.auditeddir:
                break
            curpath = os.path.join(self.root, prefix)
            try:
                st = os.lstat(curpath)
            except OSError as err:
                # EINVAL can be raised as invalid path syntax under win32.
                # They must be ignored for patterns can be checked too.
                if err.errno not in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL):
                    raise
            else:
                if stat.S_ISLNK(st.st_mode):
                    raise util.Abort(
                        _('path %r traverses symbolic link %r')
                        % (path, prefix))
                elif (stat.S_ISDIR(st.st_mode) and
                      os.path.isdir(os.path.join(curpath, '.hg'))):
                    if not self.callback or not self.callback(curpath):
                        raise util.Abort(_("path '%s' is inside nested "
                                           "repo %r")
                                         % (path, prefix))
            prefixes.append(normprefix)
            parts.pop()
            normparts.pop()

        self.audited.add(normpath)
        # only add prefixes to the cache after checking everything: we don't
        # want to add "foo/bar/baz" before checking if there's a "foo/.hg"
        self.auditeddir.update(prefixes)