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

Is there a way to change the directory on a per thread basis instead of for the entire application? #70

Closed
patchthecode opened this issue Oct 9, 2018 · 2 comments

Comments

@patchthecode
Copy link

Commands can't change the context they run in (or anything else internally in your application) so e.g. main.run("cd", "somedirectory") will achieve nothing. Use main.currentdirectory = "somedirectory" instead, this changes the current working directory for the entire application.

I'm not sure if this might be a problem, but i'm asking before i code it.
I might have multiple threads running, and they may change the directory before running other commands. It would be bad if changing the directory changes it for the entire application because there will be conflicts on different threads.

Is my concern valid?
Thanks.

@kareman
Copy link
Owner

kareman commented Oct 10, 2018

Yes, that is definitely a valid concern. You work around it by using custom contexts instead of ‘main’, maybe one per thread:

var context = CustomContext(main) 
context.currentdirectory = ...

context.run(...)

You can also change other properties of the contexts like environment variables and their input and outputs. Also be aware that when you change the current directory of ‘main’ it also affects some Foundation classes like URL.

@patchthecode
Copy link
Author

Awesome, i didnt know you could do that.
thanks again.
closing this.

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

No branches or pull requests

2 participants