1 | """
|
2 | path_stat.py - Functions from os.path that import 'stat'.
|
3 |
|
4 | We want to keep bin/osh_parse free of I/O. It's a pure stdin/stdout filter.
|
5 | """
|
6 | import posix_ as posix
|
7 | import stat
|
8 |
|
9 |
|
10 | def exists(path):
|
11 | # type: (str) -> bool
|
12 | """Test whether a path exists. Returns False for broken symbolic links"""
|
13 | try:
|
14 | posix.stat(path)
|
15 | except posix.error:
|
16 | return False
|
17 | return True
|
18 |
|
19 |
|
20 | def isdir(s):
|
21 | # type: (str) -> bool
|
22 | """Return true if the pathname refers to an existing directory."""
|
23 | try:
|
24 | st = posix.stat(s)
|
25 | except posix.error:
|
26 | return False
|
27 | return stat.S_ISDIR(st.st_mode)
|