fidian / git-started

A good starting point for projects. Sets up lint checking, pretty printing. Easily extensible.
Other
6 stars 4 forks source link

Calling /usr/bin/stat under OSX does not function #20

Open trahma opened 9 years ago

trahma commented 9 years ago

In my case, I've used homebrew to install the common GNU utilities which puts the GNU version of stat in my path.

I forked the repo to perform a pull request and update the code to simply call "stat"but I'm assuming the || is to support a different version of stat so removing the absolute path would break that compatibility.

fidian commented 9 years ago

Could you tell me what these commands produce, even if they produce errors? Also, if you have one that works on your system, I would be happy to incorporate it.

touch some-file

# Linux
/usr/bin/stat --format=" %f%a %u:%g %s" some-file
echo "Result:  $?"

# Mac
/usr/bin/stat -f " %p %u:%g %z" some-file
echo "Result: $?

# Yours?
stat --format=" %f%a %u:%g %s" some-file
echo "Result:  $?"

rm some-file

I believe the second stat exists for Mac's built-in stat and that would be overridden for you, thus the third command above would likely work. I think the solution would be to always use /usr/bin/stat and I can just add /usr/bin to the second stat call to make everything work

The output from mine:

 81b4664 1000:1000 0
Result: 0
stat: cannot read file system information for ‘ %p %u:%g %z’: No such file or directory
  File: "some-file"
    ID: ef51bcdfae1ba2da Namelen: 143     Type: ecryptfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 238151661  Free: 135136694  Available: 123033526
Inodes: Total: 60497920   Free: 58268744
Result: 1
 81b4664 1000:1000 0
Result: 0
trahma commented 9 years ago

Here's the output from those commands:

$ touch some-file

$ # Linux
$ /usr/bin/stat --format=" %f%a %u:%g %s" some-file
/usr/bin/stat: illegal option -- -
usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]
$ echo "Result: $?"
Result: 1

$ # Mac
$ /usr/bin/stat -f " %p %u:%g %z" some-file
 100644 1614071858:184630988 0
$ echo "Result: $?"
Result: 0

$ # Yours?
$ stat --format=" %f%a %u:%g %s" some-file
 81a4644 1614071858:184630988 0
$ echo "Result: $?"
Result: 0

$ rm some-file

I stumbled across this issue while while trying to commit. I recreated the error to grab the message earlier:

myfile.phpstat: cannot read file system information for ‘ %p %u:%g %z’: No such file or directory
stat: cannot read file system information for ‘ %p %u:%g %z’: No such file or directory

I believe the issue is the code in the stat_file() function is assuming to run stat from $PATH if /usr/bin/stat doesn't exist. The issue on OSX is that stat is already in /usr/bin.

fidian commented 9 years ago

I believe this latest commit fixes the issues you are seeing. Would you be able to confirm that committing works as expected for you?