-
Notifications
You must be signed in to change notification settings - Fork 211
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
Absolute and relative paths #1797
Comments
Question for this suggestion. For |
Which is, honestly, also not a great design choice. If a program is running, it has a current directory. That's an attribute of live processes. The filesystem doesn't exist in a vacuum. A running program's active directory shouldn't be limited to a single API. That's most of my problem, actually - it currently is, but that doesn't make sense. |
What about program executed by different program from rednet message? Or program executed by |
They do, or at least they should. When you run |
Yeah, the way paths are handled within CC has been a long-standing complaint of mine. It's confusing, and very easy to get wrong (indeed, even CC screws this up). Unfortunately, it's not obvious to me how best to fix this. I think there's two separate issues here:
This is definitely workaroundable. You can do something similar to OC, and have some hidden global state that stores the current working directory, and set/restore that whenever a program is resumed/yielded. |
I feel like this is just a symptom of the problem rather than a reason not to fix it. Take a gander at code that uses fs.getDir. There seems to be a lot more instances of brute forcing the path to be absolute |
Only if that code is executing from outside of the filesystem root, to be fair. For all programs, running from The issues with On the other hand, a new API with the same methods that do operate with properly formed paths would mean a whole second place that needs to be kept updated alongside the first, even if it wouldn't require copying all the code. My existing project defines a -- Most wrapped functions only need to resolve a single given path
-- and then pass it directly to the underlying fs method
for _, func in ipairs(singlePathArgumentMethods) do
fslib[func] = function(name, ...) return fs[func](path.cwd(name), ...) end
end It may be time to decide how important backwards-compatibility is for old CC programs. |
Sorry if I step on somebody's toes, I just found this topic. A complete solution should include quite a few moments, if you ask me. |
I'm going to be honest: path handling in CC is kind of atrocious right now.
The
fs
andio
APIs use absolute paths, theshell
API handles relative ones, and only functions that are specifically built to handle relative paths differentiate between absolute-style with a leading/
and relative-style without. Any functions that don't simply assume that all paths are absolute. If you callshell.resolve(path)
from outside the root, it returns what looks for all the world like a relative path, and if you don't keep track of which paths you've resolved and which you haven't, you'll easily end up mangling them. Right now, unless you know how a specific program handles its paths, it's just not safe to call programs from anywhere but the root, since that's the only place where it doesn't matter either way.I've been writing a custom path handling API, on top of which I've been further building a custom
fs
API that specifically recognises absolute paths as beginning with a/
, but this is really just a personal band-aid solution for a fundamental problem with CC itself: inconsistent path handling makes it easy for things to break.I know it would be a fairly significant task, but I'm officially submitting a request that path handling be reworked for consistency, making all APIs support both relative and absolute paths, differentiating based on the presence or absence of a leading
/
.I'm aware that, if handled incorrectly, this could break existing (poorly-written) programs that rely on
fs
andio
treating even relative-looking paths as absolute. To that end, perhaps a new pair of APIs could be implemented as a sort of compatibility layer, such asabsfs
andabsio
. On the other hand, since running programs from the root makes it irrelevant and that's how most users run their programs, it may not be enough of a break to actually matter.The text was updated successfully, but these errors were encountered: