-
Notifications
You must be signed in to change notification settings - Fork 147
Allow ubireader_list_files to recursively list files under a path
#118
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
base: main
Are you sure you want to change the base?
Conversation
ubireader/ubifs/list.py
Outdated
|
|
||
|
|
||
| def find_dir(inodes: Mapping[int, _Inode], inum: int, names: list[str], idx: int) -> int | None: | ||
| def find_dir(inodes: Mapping[int, _Inode], inum: int, names: Sequence[str], idx: int) -> int | None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was Sequence used instead of list? I know Sequence is more generic, but list was already there, and I do not see the reason to pull in Sequence just to be more generic in a script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a change I forgot to revert. At one point I was passing down a tuple (specifically Path.parts) into this function. This required the change to Sequence to allow for tuples.
Since that's no longer necessary, I will revert this change.
ubireader/ubifs/list.py
Outdated
| if len(names) == 0: | ||
| return 1 | ||
| for dent in inodes[inum]['dent']: | ||
| for dent in inodes[inum].get('dent', []): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This made me think: what was broken here, and how is it a fix?
I think the reason it was changed was, that names is a sequence of path parts, where one of them could point to a file (instead of a directory), which has no dent.
However I think, that a more direct solution would be to check for the type of inode earlier, and return None if it is not a directory.
Looking at inode type also lets us optionally resolve and follow parts if they are pointing to symlinks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _Inode type is marked as total=False so my IDE keeps complaining that 'dent' might be missing from the dictionary. To my knowledge there's nothing wrong with the current implementation, it's just a limitation of the type checking.
I guess a better fix would be to have multiple Inode types with different "required" keys, but for now I will revert the change in this PR.
74e2c7b to
dee92a9
Compare
e1e32df to
b6ad0e6
Compare
The default output of ubireader_list_files remains the same, but when you add '--recursive' it will recursively list all the inodes under the listpath. It then also displays the absolute path to the files instead of just the name.
b6ad0e6 to
e2f6845
Compare
This is based on top of #117, but I'm happy to rebase it.