jorgebucaran / fisher

A plugin manager for Fish
https://git.io/fisher
MIT License
7.53k stars 257 forks source link

fisher copies entire disk after install #761

Closed jimvandervoort closed 1 year ago

jimvandervoort commented 1 year ago

During upgrade from fisher 3.x I noticed fisher tried to copy Safari.app, I thought this was very strange so hit Control-C. After that I still got messages in my console about cp failing because of permission denied errors.

[I] ~/c/s/dev-scripts (main) ⟩ fisher self-uninstall                                                                                                                               (aws: jim) 
removing ~/.cache/fisher
removing ~/.config/fisher
removing ~/.config/fish/functions/fisher.fish
removing ~/.config/fish/completions/fisher.fish
removing ~/.config/fish/conf.d/fisher.fish
removing ~/.config/fish/fishfile
[I] ~/c/s/dev-scripts (main) ⟩ curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher $plugins                                                              (aws: jim) 
fisher install version 4.4.3
Fetching https://api.github.com/repos/jorgebucaran/fisher/tarball/HEAD
Fetching https://api.github.com/repos/brgmnn/fish-docker-compose/tarball/HEAD
cp: /Applications/Safari.app: could not copy extended attributes to /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/Applications/Safari.app: Operation not permitted
^C⏎                                                                                                                                                                                         
[I] ~/c/s/dev-scripts (main) (1m 7s) [130] ⟩ bat ^C                                                                                                                                (aws: jim) 
[I] ~/c/s/dev-scripts (main) (1m 7s) [130] ⟩ vim /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/Applications/Safari.app                                             (aws: jim) 
[I] ~/c/s/dev-scripts (main) ⟩ vim /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/Applications/^C                                                                   (aws: jim) 
[I] ~/c/s/dev-scripts (main) ⟩ fisher                                                                                                                                              (aws: jim) 
Usage: fisher install <plugins...>  Install plugins
       fisher remove  <plugins...>  Remove installed plugins
       fisher update  <plugins...>  Update installed plugins
       fisher update                Update all installed plugins
       fisher list    [<regex>]     List installed plugins matching regex
Options:
       -v or --version  Print version
       -h or --help     Print this help message
Variables:
       $fisher_path  Plugin installation path. Default: ~/.config/fish
[I] ~/c/s/dev-scripts (main) ⟩ fisher ls                                                                                                                                           (aws: jim) 
[I] ~/c/s/dev-scripts (main) [1] ⟩ fishercp: /bin: unable to copy extended attributes to /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/bin: Operation not permitted(aws: jim) 
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/console: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/tty: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/null: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/zero: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/klog: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/oslog: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/oslog_stream: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/fd/0: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/fd/1: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/fd/2: Operation not permitted
cp: /dev/fd/3: directory causes a cycle
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/auditsessions: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/auditpipe: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/pf: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/pfm: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/ttyp0: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/ptyp0: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/ttyp1: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/ptyp1: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/ttyp2: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/ptyp2: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/ttyp3: Operation not permitted
cp: mknod: /var/folders/z_/yvxtl91j4x53wsyd3ksrm3zm0000gn/T/tmp.83C5SvSk/dev/ptyp3: Operation not permitted

(that went on for a while)

I got a bit worried that something malicious was going on, but then I typed in jobs and saw:

[I] ~/c/s/dev-scripts (main) [1] ⟩ jobs                                                                                                                                            (spaaza) 
Job     Group   State   Command
2       91675   running $fish_path --command "
                    if test -e $plugin
                        command cp -Rf $plugin/* $source
                    else
                        set temp (command mktemp -d)
                        set repo (string split -- \@ $plugin) || set repo[2] HEAD

                        if set path (string replace --regex -- '^(https://)?gitlab.com/' '' \$repo[1])
                            set name (string split -- / \$path)[-1]
                            set url https://gitlab.com/\$path/-/archive/\$repo[2]/\$name-\$repo[2].tar.gz
                        else
                            set url https://api.github.com/repos/\$repo[1]/tarball/\$repo[2]
                        end

                        echo Fetching (set_color --underline)\$url(set_color normal)

                        if curl --silent -L \$url | tar -xzC \$temp -f - 2>/dev/null
                            command cp -Rf \$temp/*/* $source
                        else
                            echo fisher: Invalid plugin name or host unavailable: \\\"$plugin\\\" >&2
                            command rm -rf $source
                        end

                        command rm -rf \$temp
                    end

                    set files $source/* && string match --quiet --regex -- .+\.fish\\\$ \$files
                " &

Could it be that in one of the lines command cp -Rf $plugin/* $source $plugin is empty thus fisher tries to copy the entire root directory to $source?

I killed the background job after this.

Does fish have an option like bash set -u (exit if undefined variable referenced)? I think fisher would be improved if it could use such an option.

jorgebucaran commented 1 year ago

Could it be that in one of the lines command cp -Rf $plugin/* $source $plugin is empty thus fisher tries to copy the entire root directory to $source?

If the issue is reproducible, then we can investigate further, but if not, adding a check to abort when an undefined variable is referenced should help prevent similar errors in the future. How does that sound?

jimvandervoort commented 1 year ago

Yes apologies for not adding better steps to reproduce @jorgebucaran, will see if I can manage to make this reproducible when I have time later this week.

jorgebucaran commented 1 year ago

Would you mind sharing your config.fish here? I'm thinking there might be something in there that's causing a hiccup with Fisher. Honestly, I doubt it's a Fisher issue or something we can fix on our side, but let's take a look anyway!

jimvandervoort commented 1 year ago

Sure!

# set -x LANG "en_GB.UTF-8"

# Set abbreviations if not set
if not set -q abbrs_initialized
  echo -n 'Setting abbreviations... '

  abbr cra 'cordova run android --device'
  abbr cri 'cordova run ios --device'
  abbr gpu 'git push --set-upstream origin (git rev-parse --abbrev-ref HEAD)'
  abbr gp 'git push'
  abbr gc 'git checkout'
  abbr cpa 'cordova prepare android'
  abbr ad 'adb devices'
  abbr aw 'adb wait-for-usb-device'
  abbr cdv cordova
  abbr cpi 'cordova prepare ios'
  abbr gd 'git diff'
  abbr ya 'yarn add'
  abbr yw 'yarn watch'
  abbr mvc 'mvn clean install'
  abbr hm 'history merge'
  abbr gs 'git status'
  abbr gst 'git stash --include-untracked'
  abbr gl 'git pull'
  abbr g git
  abbr gi git
  abbr gf 'git fatus'
  abbr taco 🌮
  abbr vi vim
  abbr v vim
  abbr port 'lsof -n -i:'
  abbr mci 'mvn clean install'
  abbr d 'docker'
  abbr dc docker-compose
  abbr ga 'git add'
  abbr branch 'git rev-parse --abbrev-ref HEAD'
  abbr y yarn
  abbr x xargs
  abbr gn 'git --no-pager'
  abbr gnd 'git --no-pager diff'
  abbr gco 'git checkout'
  abbr gpf 'git push --force-with-lease'
  abbr tf 'terraform'
  abbr t 'terraform'
  abbr c 'code .'
  abbr ns 'kubectl ns'
  abbr k kubectl
  abbr e exa
  abbr ye 'yarn exec'
  abbr i 'idea'
  abbr gap 'git add -p'

  set -U abbrs_initialized
  echo 'Done 👍'
end

abbr -a !! --position anywhere --function last_history_item
abbr -a @@ --position anywhere --function last_history_args
abbr -a awk1 --position anywhere "awk '{ print \$1 }'"
abbr gap 'git add -p'
abbr -a grst 'git restore --staged'

set fish_greeting

# Command aliases
alias diff 'colordiff'
alias poweroff "sudo shutdown -h now"
alias reboot "sudo shutdown -r now"
alias 🌮 'taco'
alias dnsflush 'sudo dscacheutil -flushcache; and sudo killall -HUP mDNSResponder'
alias vim nvim
alias pd prevd
alias nd nextd
alias :q exit # 🤓
alias browsh 'docker run --rm -it browsh/browsh'
alias yat 'bat -l yaml'
alias jat 'bat -l json'
alias spaazadate "date '+%Y%m%d'"
alias pr 'gh pr view --web'

# App aliases
alias studio "open -a \"Android Studio\""
alias sublime "open -a \"Sublime Text\""
alias xcode "open -a \"Xcode\""
alias appcode "open -a \"AppCode\""
alias sourcetree "open -a \"SourceTree\""
alias storm "open -a \"PhpStorm\""

# Android devices
alias galaxy 'printf 9886274b464b314b4b'
alias nexus 'printf 090bcc1c0182ddf4'
alias moto 'printf ZY223H9XCB'

# If using kitty, install the kitty term profile in the machine we ssh into
if [ "$TERM" = "xterm-kitty" ]
  alias ssh "kitty +kitten ssh"
  alias imgcat "kitty +kitten icat"
  alias icat "kitty +kitten icat"
end

# Neovim colors
set -x NVIM_TUI_ENABLE_TRUE_COLOR 1

# Colored man pages
if status --is-interactive
  set -x LESS_TERMCAP_md (printf "\e[01;31m")
  set -x LESS_TERMCAP_me (printf "\e[0m")
  set -x LESS_TERMCAP_se (printf "\e[0m")
  set -x LESS_TERMCAP_so (printf "\e[01;44;33m")
  set -x LESS_TERMCAP_ue (printf "\e[0m")
  set -x LESS_TERMCAP_us (printf "\e[01;32m")
end

# vi keybindings
fish_vi_key_bindings

# Default editor
set -x EDITOR nvim

# Default user for cmorrell theme
set -x default_user jim

# Add home bin to PATH
set -x PATH ~/bin $PATH

# Go bin
set -x PATH ~/code/go/bin $PATH

# Krew
set -x PATH $PATH "$HOME/.krew/bin"

# Rust
# set -x PATH "$HOME/.cargo/bin" $PATH

# Configure homebrew in $PATH
/opt/homebrew/bin/brew shellenv | source
set -x PATH /usr/local/sbin $PATH

# Python 🐍
set -x PATH /usr/local/opt/python/libexec/bin $PATH

# Init pyenv
#if status --is-interactive
  #source (pyenv init -|psub)
  #source (pyenv virtualenv-init -|psub)
#  source (rbenv init -|psub)
#end

set -x GOPATH ~/code/go

set -x PATH $PATH /opt/homebrew/opt/libpq/bin

# asdf version manager
# set -x ASDF_HASHICORP_OVERWRITE_ARCH amd64
source /opt/homebrew/opt/asdf/libexec/asdf.fish

# Use newer curl from homebrew (TLSv1.3 anyone?)
set -x PATH /opt/homebrew/opt/curl/bin $PATH

doctl completion fish | source

# Yarn global packages
set -x PATH "$HOME/.config/yarn/global/node_modules/.bin" $PATH

set -x GPG_TTY (tty)

set -x AWS_PAGER jq

#set -x GODEBUG asyncpreemptoff=1

set -x TERRAGRUNT_INCLUDE_EXTERNAL_DEPENDENCIES true
#set -x TERRAGRUNT_LOG_LEVEL error

set -x PATH $PATH ~/Library/Android/sdk/platform-tools
set -x PATH $PATH ~/Library/Android/Sdk/emulator
jimvandervoort commented 1 year ago

In conf.d I have two functions that I use in my prompt later

function preexec_time --on-event "fish_preexec"
  set -g _command_start_time (date +"%s")
end
function postexec_time --on-event "fish_postexec"
  set -l curr_time (date +"%s")
  set -g _command_run_time (math $curr_time-$_command_start_time)
end

And a bunch of stuff in ~/config/fish/functions

jorgebucaran commented 1 year ago

Can you still reproduce this if you comment out all the code?

jimvandervoort commented 1 year ago

I haven't been able to reproduce this yet, will try now.

jimvandervoort commented 1 year ago

I tried to reproduce last week too, did not figure it out. I suspect this might only happen when upgrading from 3.x

jimvandervoort commented 1 year ago

I'll remove 4.x and install 3.x and upgrade again.

jimvandervoort commented 1 year ago

Upgrade went smooth, cannot reproduce anymore @jorgebucaran . Should we close this issue?

Before I forget thanks a lot for responding here and thanks for creating such a useful public project! :)

jorgebucaran commented 1 year ago

Let's close this for now, but feel free to reopen if anything seems fishy. I'm glad to hear that you're enjoying Fisher! 😉