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

Quote all the paths to OPAMROOT when creating the init scripts on Unix #5841

Merged
merged 3 commits into from Feb 19, 2024

Conversation

kit-ty-kate
Copy link
Member

Fixes #5804

I personally think keeping the Windows style paths on Windows when using cygwin shell is fine, however none of the paths were previously quoted which is a big issue and the reason why the user in #5804 looked in the file in the first place as such command will always fail on Windows.

On cmd and powershell double quoting is apparently enough to make sure the string can't escape its context (?) (e.g. " and $ are not valid file characters)

Copy link
Collaborator

@rjbou rjbou left a comment

Choose a reason for hiding this comment

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

The code changes are good for me!
It would be better to have in the shell files unix-like paths (transformed via cygpath) instead of windows ones, even if it is understandable by cygwin.

Copy link
Collaborator

@rjbou rjbou left a comment

Choose a reason for hiding this comment

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

Updated accordingly, it then needs another review :)

@kit-ty-kate
Copy link
Member Author

Why did you remove the calls to OpamStd.Env.escape_single_quotes ? Is the cygpath function doing this job instead?

@rjbou
Copy link
Collaborator

rjbou commented Feb 16, 2024

There is no need to escape them for printing, as cygpath will output the path with slashes. And cygpath function don't need to have a single escaped input.

@kit-ty-kate
Copy link
Member Author

what happens on unix though? (when cygpath is not present)

@rjbou
Copy link
Collaborator

rjbou commented Feb 16, 2024

tested on cygwin shell

------------------
./opam/opam-init/init.cmd
------------------
if exist "C:\Users\opam\.opam\opam-init\variables.cmd" call "C:\Users\opam\.opam\opam-init\variables.cmd" >NUL 2>NUL

------------------
./opam/opam-init/init.csh
------------------
if ( $?prompt ) then
  if ( -f '/cygdrive/c/Users/opam/.opam/opam-init/env_hook.csh' ) source '/cygdrive/c/Users/opam/.opam/opam-init/env_hook.csh' >& /dev/null
endif

if ( -f '/cygdrive/c/Users/opam/.opam/opam-init/variables.csh' ) source '/cygdrive/c/Users/opam/.opam/opam-init/variables.csh' >& /dev/null

------------------
./opam/opam-init/init.fish
------------------
if isatty
  source '/cygdrive/c/Users/opam/.opam/opam-init/env_hook.fish' > /dev/null 2> /dev/null; or true
end

source '/cygdrive/c/Users/opam/.opam/opam-init/variables.fish' > /dev/null 2> /dev/null; or true

------------------
./opam/opam-init/init.ps1
------------------
. "C:\Users\opam\.opam\opam-init\variables.ps1" *> $null

------------------
./opam/opam-init/init.sh
------------------
if [ -t 0 ]; then
  test -r '/cygdrive/c/Users/opam/.opam/opam-init/complete.sh' && . '/cygdrive/c/Users/opam/.opam/opam-init/complete.sh' > /dev/null 2> /dev/null || true

  test -r '/cygdrive/c/Users/opam/.opam/opam-init/env_hook.sh' && . '/cygdrive/c/Users/opam/.opam/opam-init/env_hook.sh' > /dev/null 2> /dev/null || true
fi

test -r '/cygdrive/c/Users/opam/.opam/opam-init/variables.sh' && . '/cygdrive/c/Users/opam/.opam/opam-init/variables.sh' > /dev/null 2> /dev/null || true

------------------
./opam/opam-init/init.zsh
------------------
if [[ -o interactive ]]; then
  [[ ! -r '/cygdrive/c/Users/opam/.opam/opam-init/complete.zsh' ]] || source '/cygdrive/c/Users/opam/.opam/opam-init/complete.zsh' > /dev/null 2> /dev/null

  [[ ! -r '/cygdrive/c/Users/opam/.opam/opam-init/env_hook.zsh' ]] || source '/cygdrive/c/Users/opam/.opam/opam-init/env_hook.zsh' > /dev/null 2> /dev/null
fi

[[ ! -r '/cygdrive/c/Users/opam/.opam/opam-init/variables.sh' ]] || source '/cygdrive/c/Users/opam/.opam/opam-init/variables.sh' > /dev/null 2> /dev/null

reminds me of #5036, that tried to add init scripts tests

@rjbou
Copy link
Collaborator

rjbou commented Feb 16, 2024

what happens on unix though? (when cygpath is not present)

get_cygpath_path_transform is a no-op (identity)

@kit-ty-kate
Copy link
Member Author

what happens on unix though? (when cygpath is not present)

get_cygpath_path_transform is a no-op (identity)

in that case this is a problem and OpamStd.Env.escape_single_quotes is still required

@rjbou
Copy link
Collaborator

rjbou commented Feb 16, 2024

Oh, i didn't see that it was an addition for the quoting. Yes, it is needed!

@rjbou
Copy link
Collaborator

rjbou commented Feb 16, 2024

Updated

@rjbou
Copy link
Collaborator

rjbou commented Feb 19, 2024

thanks!

@kit-ty-kate kit-ty-kate merged commit 3179157 into ocaml:master Feb 19, 2024
28 of 29 checks passed
Opam 2.2.0 automation moved this from For beta2 to Done Feb 19, 2024
@kit-ty-kate kit-ty-kate deleted the env-quote-path-unix branch February 19, 2024 19:42
@rjbou
Copy link
Collaborator

rjbou commented Feb 26, 2024

Bench tests failing as service was on available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Opam 2.2.0
  
Done
Development

Successfully merging this pull request may close these issues.

opam init create a weird .bash_profile from a Cygwin point of view
2 participants