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

Add support for reading files to file-explorer #47

Merged

Conversation

ian-h-chamberlain
Copy link
Member

@ian-h-chamberlain ian-h-chamberlain commented Feb 12, 2022

Ref Meziu/rust-horizon#11
edit: linked wrong issue because #11 on this repo is also related to filesystem, lol

Issues I've found so far:

  • PathBuf::parent / PathBuf::pop seems to have strange behavior with the romfs:/ prefix. See my comment on File not readable Meziu/rust-horizon#11
  • File size is definitely borked for romfs. On my system, all files and directories in the romfs have the same size, but it's different per invocation of the app... I'm guessing some kind of UB is happening here
  • Due to above issue, fs::read_to_string doesn't work. Perhaps ideally, we'd have a test for both in std or in this library.

Tasks to probably address before merging:

@Meziu @AzureMarker

Just for fun, display file mode as well as size, and simplify code with
`fs::read_to_string()`, which works with the corresponding libc changes.
@@ -74,8 +75,37 @@ impl<'a> FileExplorer<'a> {
}

fn print_menu(&mut self) {
println!("Viewing {}", self.path.display());
match std::fs::metadata(&self.path) {
Copy link
Member

Choose a reason for hiding this comment

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

I see this error after reading romfs:/test-file.txt:

Failed to read romfs:: Illegal byte sequence (os error 138)

This is probably due to the weird path handling? Maybe we should handle this case in the code until the underlying path issue is fixed?

Copy link
Member Author

@ian-h-chamberlain ian-h-chamberlain Feb 14, 2022

Choose a reason for hiding this comment

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

Yes, this is because of Meziu/rust-horizon#13 as far as I know. I didn't want it to block this PR because I think it was an issue before but got more exposed by this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, not blocking, but maybe we can do something like in run with self.path.components().count() > 1 to avoid popping the path in this case. Or maybe we just need to reset it manually. Up to you.

match std::fs::read_to_string(&self.path) {
Ok(contents) => {
println!("File contents:\n{0:->80}", "");
println!("{contents}");
Copy link
Member

Choose a reason for hiding this comment

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

Interestingly, for a really long file this takes a noticeably long amount of time (30 seconds on my /retroarch/retroarch.cfg), during which you see the lines scroll past pretty quickly. I wonder if the libctru console implementation is slow or something?

Copy link
Member Author

Choose a reason for hiding this comment

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

How big is that file, out of curiosity? I only tested with this small one but anything on the order of 30s seems worth investigating. In particular I would not expect romfs to be slow, but I haven't looked too close at the io implementations for it...

Copy link
Member

@AzureMarker AzureMarker Feb 14, 2022

Choose a reason for hiding this comment

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

It's 104 KB. I think it's just the default config, but here is the exact file (compressed so GitHub accepts it):
retroarch_config.zip

Copy link
Member

Choose a reason for hiding this comment

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

Yep, it looks like that they really needed a scroll effect, but since the console cooperative thread doesn’t yield the scroll blocks the whole app, and takes quite a while, too.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, the scroll effect is semi-intentional? I guess fixing that would require libctru changes...

match std::fs::read_to_string(&self.path) {
Ok(contents) => {
println!("File contents:\n{0:->80}", "");
println!("{contents}");
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should paginate the output here too? I wonder if we should move the pagination message to the lower screen to avoid interrupting the top screen's output.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, good point, I think when I had BufReader here it made more sense but using read_to_string is probably questionable when trying to paginate. Using the bottom screen to prompt for it probably takes a little work but sounds like a potentially nicer UX for this example.

Copy link
Member

Choose a reason for hiding this comment

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

I think the prompt move should be as making a new temporary console and selecting it.

@Meziu Meziu merged commit 3dedcd9 into rust3ds:master Feb 25, 2022
@ian-h-chamberlain ian-h-chamberlain deleted the file-explorer/read-file-contents branch February 24, 2024 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants