-
Notifications
You must be signed in to change notification settings - Fork 18k
path/filepath: filepath.Join() removes dir if it is just a dot #70711
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
Comments
Imo A safe solution would need to be more complex than leading I'm also curious why your current workaround is not portable, afait it produce valid paths on everything but windows, however I would be surprised if you are invoking bash on windows. |
Hmm, now that you wrote it, I have to admit that this is indeed true :) However, I also tried another workaround (a better one to my taste): I am checking if the given parameter is an existing file and in that case I call it directly: if collector.Script != "" {
// run directly
cmd = exec.Command(collector.Script)
} else {
// pipe code into bash
cmd = exec.Command("bash")
cmd.Stdin = strings.NewReader(collector.Code)
} So now with scripts, there's no bash involved anymore. But the error persists of course:
So I think I'm going to modify |
No, I am using So, from my point of view, this could be closed. And thanks a lot for the amazingly fast response! |
✨ if someone else would care about this it could be reopened. |
Go version
go version go1.22.1 linux/amd64
Output of
go env
in your module/workspace:What did you do?
I am working on an inhouse commandline client to generate PDF reports. The client supports various input options, one of them is an auto discover feature. Users call it like
-a <dir>
. The client then digs through the given directory for various kinds of evidence to included into the report. One possibility are shell scripts which will be executed. I execute those by piping the script name into a bash call, like:The reason is, that it is also possible to specify a shell command directly using another option (
-e "kubectl get pods"
), which runs the same code.The script name will be concatenated using
filepath.Join(dir, file)
.So, this all works fine and dandy, but if the user executes it inside the current directory and specifies
-a .
, then the.
will be removed byfilepath.Join()
.In almost all thinkable cases this might be the expected behavior. However, since I am piping the script name into bash's STDIN, bash then considers it to be a command and because there's no path component it searches it in
$PATH
, which of course fails, e.g.:So, my current workaround looks like this:
This works, but isn't portable anymore.
I'd like to have a portable solution without me writing code to verify the runtime operating system, if possible.
Thanks in advance,
Tom
What did you see happen?
While I understand the current behavior, it is not documented and is an decision I am unable to influence. Yes, changing the behavior will break existing code, so this would or course not be an option. But maybe you can consider to add some kind of flag so that one is able to force join a single dot directory, or something like that.
What did you expect to see?
See description above.
The text was updated successfully, but these errors were encountered: