Exemplo n.º 1
0
    def _dirEntryToFileInfo(dirEntry: os.DirEntry, path: str, realpath: str):
        try:
            linkname = os.readlink(realpath) if dirEntry.is_symlink() else ""
        except OSError:
            linkname = ""

        return FolderMountSource._statsToFileInfo(
            dirEntry.stat(follow_symlinks=False), linkname, path)
Exemplo n.º 2
0
 def _get_entry_attributes(entry: os.DirEntry):
     attrs = FileAttributes.NONE
     if entry.is_dir():
         attrs |= FileAttributes.IS_DIR
     elif entry.is_file():
         attrs |= FileAttributes.IS_FILE
     if entry.is_symlink():
         attrs |= FileAttributes.IS_LINK
     if entry.name.startswith('.'):
         attrs |= FileAttributes.IS_HIDDEN
     return attrs
Exemplo n.º 3
0
 def should_hard_link_file_DirEntry(self, a_file: os.DirEntry):
     assert isinstance(a_file, os.DirEntry)
     retVal = False
     if self.hard_links and not self.hard_links_failed and not a_file.is_symlink():
         for no_hard_link_pattern in self.__all_no_hard_link_patterns:
             file_path = Path(a_file)  # todo: avoid using Path.match, since converting DirEntry toPath is not efficient
             if file_path.match(no_hard_link_pattern):
                 log.debug(f"not hard linking {a_file.path} because it matches pattern {no_hard_link_pattern}")
                 break
         else:
             retVal = True
     return retVal
Exemplo n.º 4
0
    def validate_file(self, dir_entry: os.DirEntry) -> bool:
        """Validates given DirEntry. Returns False if entry should be completely ignored,
        or True if we want to keep it for further processing.

        Ignore all zero length files. There are usually there for a purpose like .dummy etc,
        so there can be tons of it with the same name even, so by default, ignore them completely.
        Also ignore all symlinks."""

        from .log import Log

        if dir_entry.is_symlink():
            Log.vv('{name}: It is the symbolic link. Skipping.'.format(
                name=dir_entry.name))
            return False

        # NOTE: do not call is_file() on DirEntry. It will fail in endless
        # recursion for invalid (dead) symbolic links. os.path.isfile() works).
        if not dir_entry.is_file():
            Log.vv('{name}: This is not a file. Skipping.'.format(
                name=dir_entry.name))
            return False

        item_size = dir_entry.stat().st_size

        if item_size == 0:
            Log.vv('{name}: File is 0 bytes long. Skipping.'.format(
                name=dir_entry.name))
            return False

        if self.min_size > 0 and item_size < self.min_size:
            Log.vv('{name}: File is shorter than min size ({size}). Skipping.'.
                   format(name=dir_entry.name, size=item_size))
            return False

        if 0 < self.max_size < item_size:
            Log.vv('{name}: File is biger than max size ({size}). Skipping.'.
                   format(name=dir_entry.name, size=item_size))
            return False

        for list_item in self._file_name_blacklist:
            match = re.match(list_item, dir_entry.name)
            if match is not None:
                Log.vv('File "{name}" blacklisted by "{re}" rule. Skipping.'.
                       format(name=dir_entry.name, re=list_item))
                return False

        return True