예제 #1
0
    def Stat(self, path=None, ext_attrs=False):
        """Returns stat information of a specific path.

    Args:
      path: a Unicode string containing the path or None.
            If path is None the value in self.path is used.
      ext_attrs: Whether the call should also collect extended attributes.

    Returns:
      a StatResponse proto

    Raises:
      IOError when call to os.stat() fails
    """
        # Note that the encoding of local path is system specific
        local_path = client_utils.CanonicalPathToLocalPath(path or self.path)
        result = client_utils.StatEntryFromPath(local_path,
                                                self.pathspec,
                                                ext_attrs=ext_attrs)

        # Is this a symlink? If so we need to note the real location of the file.
        try:
            result.symlink = utils.SmartUnicode(os.readlink(local_path))
        except (OSError, AttributeError):
            pass

        return result
예제 #2
0
 def ListFiles(self, ext_attrs=None):
     for f in os.listdir(self._AbsPath()):
         ps = self.pathspec.Copy()
         ps.last.path = os.path.join(ps.last.path, f)
         yield client_utils.StatEntryFromPath(self._AbsPath(f),
                                              self.pathspec,
                                              ext_attrs=ext_attrs)
예제 #3
0
파일: files.py 프로젝트: khanhgithead/grr
    def _Stat(
        self,
        path: Text,
        ext_attrs: bool = False,
        follow_symlink: bool = True,
    ) -> rdf_client_fs.StatEntry:
        """Returns stat information of a specific path.

    Args:
      path: A unicode string containing the path.
      ext_attrs: Whether the call should also collect extended attributes.
      follow_symlink: Whether links should be resolved.

    Returns:
      a StatResponse proto

    Raises:
      IOError when call to os.stat() fails
    """
        # Note that the encoding of local path is system specific
        local_path = client_utils.CanonicalPathToLocalPath(path)
        result = client_utils.StatEntryFromPath(local_path,
                                                self.pathspec,
                                                ext_attrs=ext_attrs,
                                                follow_symlink=follow_symlink)

        # Is this a symlink? If so we need to note the real location of the file.
        try:
            result.symlink = os.readlink(local_path)
            # Note: unlike Python 2 (raising OSError), Python 3 raises a ValueError
            # if the path in question doesn't point to a link.
        except (OSError, AttributeError, ValueError):
            pass

        return result
예제 #4
0
  def Stat(
      self,
      ext_attrs: bool = False,
      follow_symlink: bool = True,
  ) -> rdf_client_fs.StatEntry:
    """Get Stat for self.path."""
    del follow_symlink  # Unused.

    return client_utils.StatEntryFromPath(
        self._AbsPath(), self.pathspec, ext_attrs=ext_attrs)
예제 #5
0
 def Stat(self, path=None, ext_attrs=None):
     """Get Stat for self.path."""
     del path  # Unused.
     return client_utils.StatEntryFromPath(self._AbsPath(),
                                           self.pathspec,
                                           ext_attrs=ext_attrs)
예제 #6
0
 def Stat(self):
     """Get Stat for self.path."""
     return client_utils.StatEntryFromPath(self._AbsPath(), self.pathspec)