def _EntriesGenerator(self): """Retrieves directory entries. Since a directory can contain a vast number of entries using a generator is more memory efficient. Yields: EXTPathSpec: EXT path specification. """ try: fsext_file_entry = self._file_system.GetEXTFileEntryByPathSpec( self.path_spec) except errors.PathSpecError: return location = getattr(self.path_spec, 'location', None) for fsext_sub_file_entry in fsext_file_entry.sub_file_entries: directory_entry = fsext_sub_file_entry.name if not location or location == self._file_system.PATH_SEPARATOR: directory_entry = self._file_system.JoinPath([directory_entry]) else: directory_entry = self._file_system.JoinPath( [location, directory_entry]) yield ext_path_spec.EXTPathSpec( inode=fsext_sub_file_entry.inode_number, location=directory_entry, parent=self.path_spec.parent)
def GetRootFileEntry(self): """Retrieves the root file entry. Returns: EXTFileEntry: file entry. """ path_spec = ext_path_spec.EXTPathSpec( location=self.LOCATION_ROOT, inode=self.ROOT_DIRECTORY_INODE_NUMBER, parent=self._path_spec.parent) return self.GetFileEntryByPathSpec(path_spec)
def GetLinkedFileEntry(self): """Retrieves the linked file entry, e.g. for a symbolic link. Returns: EXTFileEntry: linked file entry or None if not available. """ link = self._GetLink() if not link: return None parent_path_spec = getattr(self.path_spec, 'parent', None) path_spec = ext_path_spec.EXTPathSpec(location=link, parent=parent_path_spec) is_root = bool(link == self._file_system.LOCATION_ROOT) return EXTFileEntry(self._resolver_context, self._file_system, path_spec, is_root=is_root)
def GetParentFileEntry(self): """Retrieves the parent file entry. Returns: EXTFileEntry: parent file entry or None if not available. """ parent_location = None location = getattr(self.path_spec, 'location', None) if location is not None: parent_location = self._file_system.DirnamePath(location) if parent_location == '': parent_location = self._file_system.PATH_SEPARATOR parent_path_spec = getattr(self.path_spec, 'parent', None) path_spec = ext_path_spec.EXTPathSpec(location=parent_location, parent=parent_path_spec) is_root = bool(parent_location == self._file_system.LOCATION_ROOT) return EXTFileEntry(self._resolver_context, self._file_system, path_spec, is_root=is_root)