Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve LayerFilesystem iterdir and scandir #973

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dissect/target/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,9 @@
yielded = {".", ".."}
selfentry = self._resolve()
for fsentry in selfentry.entries:
if not fsentry.is_dir():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add unit tests?

continue

Check warning on line 1539 in dissect/target/filesystem.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/filesystem.py#L1539

Added line #L1539 was not covered by tests

for entry_name in fsentry.iterdir():
name = entry_name if selfentry.fs.case_sensitive else entry_name.lower()
if name in yielded:
Expand All @@ -1550,6 +1553,9 @@
items = defaultdict(list)
selfentry = self._resolve()
for fsentry in selfentry.entries:
if not fsentry.is_dir():
continue

Check warning on line 1557 in dissect/target/filesystem.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/filesystem.py#L1557

Added line #L1557 was not covered by tests

for entry in fsentry.scandir():
name = entry.name if selfentry.fs.case_sensitive else entry.name.lower()
if name in (".", ".."):
Expand Down
9 changes: 9 additions & 0 deletions dissect/target/plugins/filesystem/walkfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
@arg("--walkfs-path", default="/", help="path to recursively walk")
def walkfs(self, walkfs_path: str = "/") -> Iterator[FilesystemRecord]:
"""Walk a target's filesystem and return all filesystem entries."""

if not self.target.fs.path(walkfs_path).exists():
JSCU-CNI marked this conversation as resolved.
Show resolved Hide resolved
self.target.log.error("No such file or directory: '%s'", walkfs_path)
return

Check warning on line 43 in dissect/target/plugins/filesystem/walkfs.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/plugins/filesystem/walkfs.py#L42-L43

Added lines #L42 - L43 were not covered by tests

if not self.target.fs.path(walkfs_path).is_dir():
self.target.log.error("Not a directory: '%s'", walkfs_path)
return

Check warning on line 47 in dissect/target/plugins/filesystem/walkfs.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/plugins/filesystem/walkfs.py#L46-L47

Added lines #L46 - L47 were not covered by tests

for entry in self.target.fs.recurse(walkfs_path):
try:
yield generate_record(self.target, entry)
Expand Down
Loading