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

ln: failed to create symbolic link #7

Closed
EtherealMochi opened this issue Jan 12, 2022 · 4 comments
Closed

ln: failed to create symbolic link #7

EtherealMochi opened this issue Jan 12, 2022 · 4 comments

Comments

@EtherealMochi
Copy link

EtherealMochi commented Jan 12, 2022

Hello! I am using your plugin-load function and I have run into an issue. I think I know where it is, but I don't know how to fix it as I am very new to ZSH. I am using chezmoi to keep all my ZSH configs the same across all of my machines. Upon initial load of zsh, there are no issues and plugins load with no problem. When copying my configs to a different machine and running zsh I get a few issues with certain plugins. The output is below:

ln: failed to create symbolic link '/config/.config/zsh/plugins/powerlevel10k/powerlevel10k.plugin.zsh': File exists
ln: failed to create symbolic link '/config/.config/zsh/plugins/z/z.plugin.zsh': File exists
ln: failed to create symbolic link '/config/.config/zsh/plugins/zsh-tailf/zsh-tailf.plugin.zsh': File exists
ln: failed to create symbolic link '/config/.config/zsh/plugins/up.zsh/up.zsh.plugin.zsh': File exists

Since the links were already created before and currently exist, why is the plugin-load function still trying to create the symbolic links? I realize that I can delete the plugin folders or delete the symbolic link that was created to get it to work on the machine I pulled my dotfiles into. It seems that the plugin load function is making symbolic links when it does not need to also, as a few of those particular plugins already come with the correct files. I have listed the default files that come with the plugins below:

https://github.com/peterhurford/up.zsh includes the file: up.plugin.zsh
https://github.com/rummik/zsh-tailf includes the file: tailf.plugin.zsh

From what I can gather, the plugin-load function thinks there are no plugin files and wants to create symbolic link because the plugin files do not contain the full repo names (up.zsh. zsh-tailf).

edit: I realize this post is kind of all over the place, sorry.

@mattmc3
Copy link
Owner

mattmc3 commented Jan 12, 2022

Interesting. This is the relevant code block:

if [[ ! -e $initfile ]]; then
initfiles=($plugin_dir/*.plugin.{z,}sh(N) $plugin_dir/*.{z,}sh{-theme,}(N))
[[ ${#initfiles[@]} -gt 0 ]] || { echo >&2 "Plugin has no init file '$repo'." && continue }
ln -s "${initfiles[1]}" "$initfile"
fi

It tests for the existence of the init file prior to creating a symlink (if [[ ! -e $initfile ]]; then). You might try adding an echo statement to help debug and get the values of the variables in question: echo initfile=$initfile plugin_dir=$plugin_dir and let me know what you find.

@EtherealMochi
Copy link
Author

EtherealMochi commented Jan 12, 2022

Interesting. This is the relevant code block:

if [[ ! -e $initfile ]]; then
initfiles=($plugin_dir/*.plugin.{z,}sh(N) $plugin_dir/*.{z,}sh{-theme,}(N))
[[ ${#initfiles[@]} -gt 0 ]] || { echo >&2 "Plugin has no init file '$repo'." && continue }
ln -s "${initfiles[1]}" "$initfile"
fi

It tests for the existence of the init file prior to creating a symlink (if [[ ! -e $initfile ]]; then). You might try adding an echo statement to help debug and get the values of the variables in question: echo initfile=$initfile plugin_dir=$plugin_dir and let me know what you find.

The echo output was showing the symlinks in initfile.

After doing some more researching I figured out what the issue is in my case. On my main machine it creates the symbolic links with the full path. When I use chezmoi to pull my config to my other machines it pulls those symbolic links as well but they are broken. Somehow that was causing the function to try and recreate the symlinks. I corrected this by changing line 20 to use relative paths instead of absolute. Now it is working on all my machines with no errors.

ln -sr "${initfiles[1]}" "$initfile"

@mattmc3
Copy link
Owner

mattmc3 commented Jan 12, 2022

Clever! The BSD ln that ships with MacOS doesn't have the -r option, so I can't incorporate that or I'd have to have everyone on MacOS brew install coreutils, so for now we'll just mark this is resolved.

@mattmc3 mattmc3 closed this as completed Jan 12, 2022
@EtherealMochi
Copy link
Author

@mattmc3 I completely understand and I have no problem with doing the change on my end only. Thanks for working with me today.

mattmc3 added a commit that referenced this issue Jan 19, 2022
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