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

Symlink require administrator on Windows #122

Closed
moeshin opened this issue Jan 6, 2022 · 72 comments
Closed

Symlink require administrator on Windows #122

moeshin opened this issue Jan 6, 2022 · 72 comments

Comments

@moeshin
Copy link
Contributor

moeshin commented Jan 6, 2022

We can:

  • Require administrator
  • Download directly as ~/.wakatime/wakatime-cli
  • link = os.path.join(getResourcesFolder(), 'wakatime-cli')
    if not os.path.exists(link):
    try:
    os.symlink(getCliLocation(), link)
    except:
    pass
    Handle exceptions by copying file
  • ...
@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

And the suffix of the executable file require be .exe in nvim.

E903: Process failed to start: no such file or directory

@alanhamlett
Copy link
Member

If you copy the file to ~/.wakatime/wakatime-cli (without .exe) does it work? We can have the install script do the same on Windows.

@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

vim work, nvim no work:

E903: Process failed to start: no such file or directory: "C:/Users/MoeShin/.wakatime/wakatime-cli"

@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

They can all work with .exe.

link = os.path.join(getResourcesFolder(), 'wakatime-cli')

if is_win:
    link += '.exe'

@alanhamlett
Copy link
Member

alanhamlett commented Jan 6, 2022

How about now, after 3bdb70e?

@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

nvim no run install_cli.py

@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

nvim no run install_cli.py

#123

@alanhamlett
Copy link
Member

alanhamlett commented Jan 6, 2022

What's your output when you run this in Vim and Nvim?

:echo &shell

We can't assume &shell always accepts argument -c from #123, so I'll push a change now for you to test.

@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

In vim (MSYS2)

echo &shell
" D:/msys64/usr/bin/zsh

echo &shellcmdflag
" -c

In nvim (MSYS2)

echo &shell
" D:/msys64/usr/bin/zsh

echo &shellcmdflag
" /s /c

In vim (CMD)

echo &shell
" C:\WINDOWS\system32\cmd.exe

echo &shellcmdflag
" /c

In nvim (CMD)

echo &shell
" cmd.exe

echo &shellcmdflag
" /s /c

@alanhamlett
Copy link
Member

I just pushed 55d42cf. Can you update and see if it fixes things for you on Vim and Nvim?

@alanhamlett
Copy link
Member

Also, thanks for &shellcmdflag I had forgotten to ask for that output too!

@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

In MSYS2

[WakaTime] 127: /usr/bin/zsh: can't open input file: /s /c
echo &shell
" D:/msys64/usr/bin/zsh

echo &shellcmdflag
" /s /c

@alanhamlett
Copy link
Member

How about now after debf1ef? Thanks for helping debug this!

@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

in MSYS2 only nvim

[WakaTime] 127: /usr/bin/zsh: can't open input file: /s

in CMD

[WakaTime] 2: /usr/bin/python3: can't open file '/c/Users/MoeShin/C:/Users/MoeShin/.vim/plugged/vim-wakatime/scripts/install_cli.py': [Errno 2] No such file or directory

By the way,I python3 install by pacman on MSYS2.

@alanhamlett
Copy link
Member

Some cleanup with 49591ed so now Vim and NVim both use the same command. Maybe this will help simplify debugging. Can you update and try it out?

@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

no change

@alanhamlett
Copy link
Member

If you revert plugin/wakatime.vim back to the state it was in from your PR #123 (1d87845) I'm curious does it work in all variants Vim/NVim/CMD/MSYS2?

@alanhamlett alanhamlett reopened this Jan 6, 2022
@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

No, it has bug.
I have rolled back and modified moeshin@3e54260

@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

The problem is in python.
Python3 installed by pacman in MSYS2, the script path require unix style.

[WakaTime] 2: /usr/bin/python3: can't open file '/c/Users/MoeShin/C:/Users/MoeShin/.vim/plugged/vim-wakatime/scripts/install_cli.py': [Errno 2] No such file or directory

@alanhamlett
Copy link
Member

So the path for install_cli.py that works in MSYS2 is this?
//c/Users/MoeShin/C//Users/MoeShin/.vim/plugged/vim-wakatime/scripts/install_cli.py

After let install_script = '/' . substitute(install_script, ':', '/', ''). Is the double slash at start necessary or does it work with a single slash? Does it work if you do this:

let install_script = "/C:/Users/MoeShin/.vim/plugged/vim-wakatime/scripts/install_cli.py"

@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

no. let install_script = "/C/Users/MoeShin/.vim/plugged/vim-wakatime/scripts/install_cli.py" is work

@alanhamlett
Copy link
Member

Can you try now after 36f7f5c?

@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

no change

@alanhamlett
Copy link
Member

That's strange, I thought it would be the fix.

Can you add line:
echo install_script just after the let install_script?

@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

install_script: C:/Users/MoeShin/.vim/plugged/vim-wakatime/scripts/install_cli.py

@alanhamlett
Copy link
Member

You've removed the override from before? Want to make sure this line is deleted:
let install_script = "/C:/Users/MoeShin/.vim/plugged/vim-wakatime/scripts/install_cli.py"

@alanhamlett
Copy link
Member

I'm not sure how it could remove the /c/Users/MoeShin/ prefix and be left with C:/ with a colon and no starting slash...

Maybe the substitute from 36f7f5c isn't running and the path changed some other way?

@moeshin
Copy link
Contributor Author

moeshin commented Jan 6, 2022

Run console

C:\Users\MoeShin>python3 C:/Users/MoeShin/.vim/plugged/vim-wakatime/scripts/install_cli.py
python3: can't open file '/c/Users/MoeShin/C:/Users/MoeShin/.vim/plugged/vim-wakatime/scripts/install_cli.py': [Errno 2] No such file or directory

@alanhamlett
Copy link
Member

I'm sorry, I had a bug in my regex. Fixed with 1316c05.

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

Run 1316c05

  • zsh+nvim(scoop)
  • zsh+vim(msys2)
  • cmd+vim(msys2)
  • zsh+vim(scoop)
[WakaTime] /usr/bin/zsh: can't open input file: /c
  • cmd+nvim(scoop)
  • cmd+vim(scoop)
[WakaTime] 2: /usr/bin/python3: can't open file '/c/Users/MoeShin/C:/Users/MoeShin/.vim/plugged/vim-wakatime/scripts/install_cli.py': [Errno 2] No such file or directory

@alanhamlett
Copy link
Member

Can you re-run those tests with a0daba9?

@alanhamlett
Copy link
Member

Also, would be helpful for each of the checkboxes above to have the values of &shell and &shellcmdflag. Just once, like your comment above please 😄

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

Run a0daba9

echom '`'.&shell.'`+`'.&shellcmdflag.'`'
  • zsh+vim(msys2)+/usr/bin/zsh+-c
  • zsh+vim(scoop)+D:/msys64/usr/bin/zsh+-c
  • zsh+nvim(scoop)+D:/msys64/usr/bin/zsh+/s /c
  • cmd+vim(msys2)+sh+-c
  • cmd+vim(scoop)+C:\WINDOWS\system32\cmd.exe+/c
  • cmd+nvim(scoop)+cmd.exe+/s /c
[WakaTime] 2: /usr/bin/python3: can't open file '/c/Users/MoeShin/C:/Users/MoeShin/.vim/plugged/vim-wakatime/scripts/install_cli.py': [Errno 2] No such file or directory

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

Currently this bug is caused by the python version (installed by pacman on msys2).
It doesn't matter whether this vim or nvim runs on msys2.


And the msys2 installation folder can be customized https://www.msys2.org/.
May not contain msys.

Enter your desired Installation Folder (short ASCII-only path on a NTFS volume, no accents, no spaces, no symlinks, no subst or network drives, no FAT).

@alanhamlett
Copy link
Member

Could you also run the same echo shell test with echo s:plugin_root_folder?

@alanhamlett
Copy link
Member

And the msys2 installation folder can be customized https://www.msys2.org/. May not contain msys.

Oh, that makes things much more difficult. I'm just worried about overwriting &shell for all Windows users, in case cmd.exe isn't in their path and we break things for someone.

We also can't run system() in the foreground during startup, but maybe we can async run python -VV.

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

cmd+vim(msys2)
s:IsMSYS(): 0
s:plugin_root_folder: /c/Users/MoeShin/.vim/plugged/vim-wakatime

cmd+vim(scoop)
s:IsMSYS(): 0
s:plugin_root_folder: C:/Users/MoeShin/.vim/plugged/vim-wakatime

cmd+nvim(scoop)
s:IsMSYS(): 0
s:plugin_root_folder: C:/Users/MoeShin/.vim/plugged/vim-wakatime

zsh+vim(msys2)
s:IsMSYS(): 0
s:plugin_root_folder: /c/Users/MoeShin/.vim/plugged/vim-wakatime

zsh+vim(scoop)
s:IsMSYS(): 1
s:plugin_root_folder: /C/Users/MoeShin/.vim/plugged/vim-wakatime

zsh+nvim(scoop)
s:IsMSYS(): 1
s:plugin_root_folder: /C/Users/MoeShin/.vim/plugged/vim-wakatime

In vim(msys2)

has('win32') == 0
has('unix') == 1

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

Or re-run with unix style path when python exit code == 2

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

I'm just worried about overwriting &shell for all Windows users, in case cmd.exe isn't in their path and we break things for someone.

Or override shellcmdflag?

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

zsh+vim(msys2)

echo &shell
" D:/msys64/usr/bin/zsh

echo &shellcmdflag
" -c

zsh+vim(scoop)

echo &shell
" D:/msys64/usr/bin/zsh

echo &shellcmdflag
" At startup:
" /c
" After startup:
" -c

zsh+nvim(scoop)

echo &shell
" D:/msys64/usr/bin/zsh

echo &shellcmdflag
" /s /c

cmd+vim(msys2)

echo &shell
" C:\WINDOWS\system32\cmd.exe

echo &shellcmdflag
" /c

cmd+vim(scoop)

echo &shell
" C:\WINDOWS\system32\cmd.exe

echo &shellcmdflag
" /c

cmd+nvim(scoop)

echo &shell
" cmd.exe

echo &shellcmdflag
" /s /c

@alanhamlett
Copy link
Member

I'm just worried about overwriting &shell for all Windows users, in case cmd.exe isn't in their path and we break things for someone.

Or override shellcmdflag?

Can't overwrite &shellcmdflag without also &shell because they're tied together:
https://vimhelp.org/options.txt.html#%27shell%27

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

if &shell =~ 'sh\(.exe\)\?$'
    let &shellcmdflag = '-c'
endif

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

if s:has_async
    if !s:IsWindows()
        let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)]
    elseif &shell =~ 'sh\(.exe\)\?$' " or &shell !~ 'cmd\(.exe\)\?$'
        let job_cmd = [&shell, '-c', s:JoinArgs(cmd)]
    else
        let job_cmd = [&shell, &shellcmdflag] + cmd
    endif
elseif s:nvim_async
    if s:IsWindows()
        let job_cmd = cmd
    else
        let job_cmd = [&shell, &shellcmdflag, s:JoinArgs(cmd)]
    endif
endif

@alanhamlett
Copy link
Member

That works for all variants?

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

if &shell =~ 'sh\(.exe\)\?$'
    let &shellcmdflag = '-c'
endif

This way has bug in nvim.

:!ls .
" no work: zsh:1: command not found: ls .

:!'ls .'
" no work: zsh:1: command not found: 'ls .'

:!"ls ."
" work

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

That works for all variants?

Yes

@alanhamlett
Copy link
Member

That works for all variants?

Yes

With that change, do we still need to replace C:/ with /C/?

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

Python msys still needs

> python3 -VV
Python 3.9.9 (main, Dec 28 2021, 11:05:23)
[GCC 11.2.0]

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

Normal python does not need

> python3 -VV
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)]

@alanhamlett
Copy link
Member

Which of the variants from #122 (comment) or #122 (comment) are python msys?

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

python doesn't affect these

@moeshin
Copy link
Contributor Author

moeshin commented Jan 7, 2022

#122 (comment)
It's two problems:

a0daba9 does not completely solve the first problem. If I use git-bash etc.

@alanhamlett
Copy link
Member

Fixed the first problem with a17a436.

Fixed the second problem with 441f5c7.

@alanhamlett
Copy link
Member

Thanks again for your help fixing this!

@moeshin
Copy link
Contributor Author

moeshin commented Jan 8, 2022

Thanks you.

a17a436 only fix job_start and jobstart.
There may also be a first problem with calling system() in nvim on bash, git-bash or zsh. #122 (comment)

echo &shell
" D:/msys64/usr/bin/zsh

echo &shellcmdflag
" /s /c

echo system('ls .')
" /usr/bin/bash: /s: No such file or directory

If overwrite let &shellcmdflag = '-c', there will be problems #122 (comment)

echo "Today: " . s:Chomp(system(s:JoinArgs(cmd)))

In nvim, the type of cmd can be string or list.

let &shellcmdflag = '-c'

echo system('ls .') " no work

echo system(['ls', '.']) " work
function! g:System(cmd)
    " cmd is list
    let override = s:false
    if has('nvim')
        if has('win32') && &shell !~ 'cmd\(.exe\)\?$' && &shellcmdflag !~ '^\s*-'
            let override = s:true
            let _shellcmdflag = &shellcmdflag
            let &shellcmdflag = '-c'
        endif
    else
        let a:cmd = s:JoinArgs(a:cmd)
    endif
    let data = system(a:cmd)
    if override
        let &shellcmdflag = _shellcmdflag
    endif
    return data
endfunction

@alanhamlett
Copy link
Member

Doesn't Nvim always have support for async? Then it would never reach system() on nvim... only on older Vim without async.

@moeshin
Copy link
Contributor Author

moeshin commented Jan 9, 2022

ok

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