This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
HarriKnox's profile picture

Use shell.setDir() to go to a fake directory

Started by HarriKnox, 21 August 2014 - 05:12 AM
HarriKnox #1
Posted 21 August 2014 - 07:12 AM
I'm currently in the process of rewriting the shell program to add my own twists to it (nothing too out of the ordinary), so I'm looking at the code of the default shell program that comes shipped with ComputerCraft to base my changes off of. As I was looking through the code of the shell program, I noticed that shell.setDir() is defined as
function shell.setDir( _sDir )
	sDir = _sDir
end
With that implementation, any program, or someone in the Lua interpreter, could run shell.setDir("/sunshineRainbowsAndUnicorns") and it would set the CWD to that directory, even though it may not exist.

Is there any particular purpose to allowing the setting of the CWD to whatever you please, be it a folder that doesn't exist or a file? I know other languages prevent being able to do that: Python, for example, raises an exception if you tried to set the CWD to an imaginary directory. In my edits, I'm considering changing the function definition to check if the directory exists before setting it (if it doesn't, then it won't change the CWD), but I don't want to do that if it would break some fundamental CC principle that I'm unaware of.
theoriginalbit #2
Posted 21 August 2014 - 07:45 AM
You are correct, you should probably add some logic to resolve and validate the path supplied when attempting to set it. I can't think of any possible use cases where you'd want to be able to set it to a location that doesn't exist, especially with how the FS API works.