chrisbra / Recover.vim

A Plugin to show a diff, whenever recovering a buffer
http://www.vim.org/scripts/script.php?script_id=3068
247 stars 25 forks source link

"stat: illegal option -- - dated" on macOS #73

Closed rpdelaney closed 2 years ago

rpdelaney commented 2 years ago

BSD stat is a very different beast than GNU stat, and BSD stat ships on macOS. My guess is that's somewhere at the root of this error.

I honestly don't know how long this has been going on, since the plugin works fine otherwise and I may not have noticed at all. It's no kind of big deal.

E325: ATTENTION
Found a swap file by the name "extinfo/.cli.py.swp"
            owned by: stat: illegal option -- -  dated: usage: stat [-FLnq] [-f format | -l | -r | -s | -x] [-t timefmt] [file ...]
         file name: ~ryan/src/me/extinfo/extinfo/cli.py
          modified: YES
         user name: ryan  host name: Ryans-MBP
        process ID: 23766
        While opening file "~ryan/src/me/extinfo/extinfo/cli.py"
           dated: Tue Apr  5 16:27:31 2022
chrisbra commented 2 years ago

Hi, I suppose this line is the error? https://github.com/chrisbra/Recover.vim/blob/a6f8d9e6086e611daf55f3fe05c06e7aaaf46f35/autoload/recover.vim#L45

rpdelaney commented 2 years ago

Looks like it. Here's the output on my macbook using the built-in BSD stat vs GNU stat (which is gstat when installed with homebrew):

$ /usr/bin/stat --printf="%U\n%Y\n" pyproject.toml
/usr/bin/stat: illegal option -- -
usage: stat [-FLnq] [-f format | -l | -r | -s | -x] [-t timefmt] [file ...]
$ gstat --printf="%U\n%Y\n" pyproject.toml
"ryan
1649172140
$

I'm not sure what would be the best way for vim-recover to detect which one is on the system, though.

chrisbra commented 2 years ago

hm, interesting. I tried to pull a freebsd docker image and it had gnu stat installed :)

Okay, how about the following patch then:

diff --git a/autoload/recover.vim b/autoload/recover.vim
index 995104f..cd1a57d 100755
--- a/autoload/recover.vim
+++ b/autoload/recover.vim
@@ -42,7 +42,7 @@ fu! s:PIDName(pid) "{{{1
   return ''
 endfu
 fu! s:AttentionMessage(swap_info, pname)
-  let statinfo = executable('stat') ? systemlist('stat --printf="%U\n%Y\n" '. a                                                 :swap_info['fname']) : []
+  let statinfo = executable('stat') && !has("bsd") ? systemlist('stat --printf=                                                 "%U\n%Y\n" '. a:swap_info['fname']) : []
   let owner = get(statinfo, 0, '')
   let time  = get(statinfo, 1, '')
   return [ 'E325: ATTENTION',
rpdelaney commented 2 years ago

I saw the commit message. To do this with BSD stat, try:

$ stat -f "%Su\n%m\n" .bashrc
ryan
1638818018
$
chrisbra commented 2 years ago

ah thanks. I couldn't bend my brain across those printf expandos that night :)

I included your change, hopefully it works.