예제 #1
0
    def read_directory(self, file_context, marker):
        entries = []
        stat = self.fs_access.entry_info(file_context.path)

        if stat["type"] == "file":
            raise NTStatusError(NTSTATUS.STATUS_NOT_A_DIRECTORY)

        # NOTE: The "." and ".." directories should ONLY be included
        # if the queried directory is not root

        # Current directory
        if marker is None and not file_context.path.is_root():
            entry = {"file_name": ".", **stat_to_winfsp_attributes(stat)}
            entries.append(entry)
        elif marker == ".":
            marker = None

        # Parent directory
        if marker is None and not file_context.path.is_root():
            parent_stat = self.fs_access.entry_info(file_context.path.parent)
            entry = {
                "file_name": "..",
                **stat_to_winfsp_attributes(parent_stat)
            }
            entries.append(entry)
        elif marker == "..":
            marker = None

        # NOTE: we *do not* rely on alphabetically sorting to compare the
        # marker given `..` is always the first element event if we could
        # have children name before it (`.-foo` for instance)
        iter_children_names = iter(stat["children"])
        if marker is not None:
            for child_name in iter_children_names:
                if child_name == marker:
                    break

        # All remaining children are located after the marker
        for child_name in iter_children_names:
            name = winify_entry_name(child_name)
            child_stat = self.fs_access.entry_info(file_context.path /
                                                   child_name)
            entry = {
                "file_name": name,
                **stat_to_winfsp_attributes(child_stat)
            }
            entries.append(entry)

        return entries
예제 #2
0
    def __init__(self, user_fs, event_bus, base_mountpoint_path, config,
                 runner, nursery):
        self.user_fs = user_fs
        self.event_bus = event_bus
        self.base_mountpoint_path = base_mountpoint_path
        self.config = config
        self._runner = runner
        self._nursery = nursery
        self._mountpoint_tasks = {}
        self._timestamped_workspacefs = {}

        if os.name == "nt":
            self._build_mountpoint_path = lambda base_path, parts: base_path / "\\".join(
                winify_entry_name(x) for x in parts)
        else:
            self._build_mountpoint_path = lambda base_path, parts: base_path / "/".join(
                parts)
예제 #3
0
def _parsec_to_winpath(path: FsPath) -> str:
    return "\\" + "\\".join(winify_entry_name(entry) for entry in path.parts)