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

support open files relative to script url parameter #17

Closed

Conversation

stepansnigirev
Copy link

If script=... parameter is provided to the editor, the simulator will try to open resources with the same path.
Example:
https://stepansnigirev.github.io/sim/?script_startup=https://gist.githubusercontent.com/stepansnigirev/d360caaca643a17989b1b41ceef417d1/raw/init_script.py&script=https://gist.githubusercontent.com/stepansnigirev/87032c693fd12eeb9dfd219535630691/raw/page.py

This page is loading the license content from the file stored in the same gist.

I also commented out print statements in imp.py as in my build I had an error that sys.stderr is not available.

@amirgon amirgon requested a review from embeddedt November 25, 2019 19:42
@amirgon
Copy link
Collaborator

amirgon commented Nov 25, 2019

@embeddedt, @pmp-p - Could you review?

fprintf(stderr," -> remote host[%s]\n", url);
int fidx = EM_ASM_INT({return wasm_file_open(UTF8ToString($0)); }, url );
char fname[20];
snprintf(fname, sizeof(fname), "cache_%d", fidx);
return fileno( fopen(fname,"r") );
} else {
// file with no ':' - might be in the script folder
int fidx = EM_ASM_INT({return wasm_file_open(UTF8ToString($0)); }, url );
Copy link
Member

Choose a reason for hiding this comment

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

We now have this line duplicated in every branch of the if statement. Can we consolidate these duplicated portions into a static function?

Copy link
Author

Choose a reason for hiding this comment

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

Oh, you are right! I will refactor.

Copy link

@pmp-p pmp-p left a comment

Choose a reason for hiding this comment

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

the changes to file.c make local files a priority, it's a caching behaviour instead of filesystem implementation :

  • caching behaviour would need more tests to be efficient.
  • That makes it impossible for user to override firmware prebuilts files.

regarding imp.py : i'm against suppressing file open logs in browser console (stderr), chrome is already hiding emscripten stderr in the "android way" ( chromium does not) and i'm wary of that.

@stepansnigirev
Copy link
Author

regarding imp.py : i'm against suppressing file open logs in browser console (stderr)

Ok, I will return it back. I just need to figure out why my mycropython is missing sys.stderr...

@stepansnigirev
Copy link
Author

stepansnigirev commented Nov 26, 2019

the changes to file.c make local files a priority, it's a caching behaviour instead of filesystem implementation

I was doing it to make sure that if the user opens the file and writes something to it, reading it will return him what he wrote.
If we will prioritize remote files over local we will always get the content of the remote file even if we wrote to this file localy.
Should we then consider these files as read only and return file access error if the user is trying to open it in write mode?

@pmp-p
Copy link

pmp-p commented Nov 26, 2019

Should we then consider these files as read only and return file access error if the user is trying to open it in write mode?

i think it's safer to always consider local filesystem as read only, and never assume one can write anywhere without an browser/user-auth at some point ( storage size is already restricted on some browsers because in fine you are writing to a ramdisk without knowing how much space is free).

I was doing it to make sure that if the user opens the file and writes something to it, reading it will return him what he wrote.

that's a good idea but maybe it need some "this file is a product of "copy-on-write"" flag to set priority over the real up2date (remote) file.

@stale
Copy link

stale bot commented Jan 27, 2020

This issue or pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 27, 2020
@embeddedt
Copy link
Member

@stepansnigirev @pmp-p Was there any consensus on the points raised above? Does this PR need further refactoring?

@stale stale bot removed the stale label Feb 2, 2020
@stepansnigirev
Copy link
Author

Yes, it needs further refactoring. I failed to compile emscripten port with warnings in stderr back then and now I don't have time to continue working on this... I think it's better to close this pull request for now. Maybe someone else will find time.

@embeddedt
Copy link
Member

Okay, no problem. Hopefully, someone takes an interest in completing this in the future! It seems that the main issue was fixing the issue with stderr.

As a note to future readers: I did make some changes to stdio handling since this PR was last worked on so that may no longer be an issue.

@embeddedt embeddedt closed this Feb 2, 2020
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.

4 participants