Skip to content

Commit f8d8109

Browse files
committed
Add fake stat stub for macOS workaround
This is an attempt to work around the BSD/GNU `stat` incompatibility for the two calls during storage tests. $ ./test/bin/stat -c %U /Users/GitHub GitHub $ ./test/bin/stat -c %U ./data ryan $ ./test/bin/stat -f '%Su' ./data ryan
1 parent 96c4883 commit f8d8109

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/bin/stat

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
3+
# this is an unbelievably narrowly constrained used case:
4+
# there's a single use of `stat` in this codebase:
5+
# calling `stat -c %U` to find the username that owns
6+
# a given path.
7+
# But this fails on macOS because macOS uses BSD stat,
8+
# not GNU stat. This very, VERY basic, very brittle
9+
# wrapper is just to work around this one specific
10+
# call to stat.
11+
12+
import sys
13+
from os import stat
14+
from pwd import getpwuid
15+
16+
def find_owner(filename):
17+
return getpwuid(stat(filename).st_uid).pw_name
18+
19+
20+
print(find_owner(sys.argv[-1]))

0 commit comments

Comments
 (0)