@@ -7,8 +7,34 @@ export ishidden
7
7
@static if Sys. isunix ()
8
8
_ishidden_unix (f:: AbstractString ) = startswith (basename (f), ' .' )
9
9
10
+ @static if Sys. isapple () || Sys. isbsd () # BDS-related
11
+ # https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/chflags.2.html
12
+ # https://opensource.apple.com/source/xnu/xnu-4570.41.2/bsd/sys/stat.h.auto.html
13
+ const UF_HIDDEN = 0x00008000
14
+
15
+ # https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/lstat.2.html
16
+ # http://docs.libuv.org/en/v1.x/fs.html # st_flags offset is at index 11, or 21 in 32-bit
17
+ const ST_FLAGS_STAT_OFFSET = 0x15
18
+ function _st_flags (f:: AbstractString )
19
+ statbuf = Vector {UInt32} (undef, ccall (:jl_sizeof_stat , Int32, ()))
20
+ ccall (:jl_lstat , Int32, (Cstring, Ptr{UInt8}), f, statbuf)
21
+ return statbuf[ST_FLAGS_STAT_OFFSET]
22
+ end
23
+
24
+ # https://github.com/dotnet/runtime/blob/5992145db2cb57956ee444aa0f0c2f3f85ee3673/src/native/libs/System.Native/pal_io.c#L219
25
+ # https://github.com/davidkaya/corefx/blob/4fd3d39f831f3e14f311b0cdc0a33d662e684a9c/src/System.IO.FileSystem/src/System/IO/FileStatus.Unix.cs#L88
26
+ _isinvisible (f:: AbstractString ) = (_st_flags (f) & UF_HIDDEN) == UF_HIDDEN
27
+
28
+ _ishidden_bsd_related (f:: AbstractString ) = _ishidden_unix (f) || _isinvisible (f)
29
+ end
30
+
31
+ include (" utils/zfs.jl" )
32
+ if iszfs () # @static breaks here
33
+ error (" not yet implemented" )
34
+ _ishidden_zfs (f:: AbstractString ) = error (" not yet implemented" )
35
+ end
10
36
11
- @static if Sys. isapple ()
37
+ @static if Sys. isapple () # macOS/Darwin
12
38
include (" utils/darwin.jl" )
13
39
14
40
# ##=== Hidden Files and Directories: Simplifying the User Experience ===##
@@ -31,30 +57,14 @@ export ishidden
31
57
# - `/tmp`—Contains temporary files created by apps and the system.
32
58
# - `/usr`—Contains non-essential command-line binaries, libraries, header files, and other data.
33
59
# - `/var`—Contains log files and other files whose content is variable. (Log files are typically viewed using the Console app.)
60
+ # TODO
34
61
35
62
36
63
#= == Case 3: Explicitly hidden files and directories ===#
37
64
# The Finder may hide specific files or directories that should not be accessed directly by the user. The most notable example of
38
65
# this is the /Volumes directory, which contains a subdirectory for each mounted disk in the local file system from the command line.
39
66
# (The Finder provides a different user interface for accessing local disks.) In macOS 10.7 and later, the Finder also hides the
40
- # `~/Library` directory—that is, the `Library` directory located in the user’s home directory.
41
-
42
- # https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/chflags.2.html
43
- # https://opensource.apple.com/source/xnu/xnu-4570.41.2/bsd/sys/stat.h.auto.html
44
- const UF_HIDDEN = 0x00008000
45
-
46
- # https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/lstat.2.html
47
- # http://docs.libuv.org/en/v1.x/fs.html # st_flags offset is at index 11, or 21 in 32-bit
48
- const ST_FLAGS_STAT_OFFSET = 0x15
49
- function _st_flags (f:: AbstractString )
50
- statbuf = Vector {UInt32} (undef, ccall (:jl_sizeof_stat , Int32, ()))
51
- ccall (:jl_lstat , Int32, (Cstring, Ptr{UInt8}), f, statbuf)
52
- return statbuf[ST_FLAGS_STAT_OFFSET]
53
- end
54
-
55
- # https://github.com/dotnet/runtime/blob/5992145db2cb57956ee444aa0f0c2f3f85ee3673/src/native/libs/System.Native/pal_io.c#L219
56
- # https://github.com/davidkaya/corefx/blob/4fd3d39f831f3e14f311b0cdc0a33d662e684a9c/src/System.IO.FileSystem/src/System/IO/FileStatus.Unix.cs#L88
57
- _isinvisible (f:: AbstractString ) = (_st_flags (f) & UF_HIDDEN) == UF_HIDDEN
67
+ # `~/Library` directory—that is, the `Library` directory located in the user’s home directory. This case is handled by `_isinvisible`.
58
68
59
69
60
70
#= == Case 4: Packages and bundles ===#
@@ -108,10 +118,12 @@ export ishidden
108
118
end
109
119
110
120
111
- #= == All cases ===#
112
- _ishidden (f:: AbstractString ) = any ((_ishidden_unix (f), _isinvisible (f), _exists_inside_package_or_bundle (f)))
113
- else
114
- _ishidden = _ishidden_unix
121
+ #= == All macOS cases ===#
122
+ _ishidden (f:: AbstractString ) = _ishidden_bsd_related (f) || _exists_inside_package_or_bundle (f)
123
+ elseif Sys. isbsd () # BSD
124
+ _hidden (f:: AbstractString ) = _ishidden_bsd_related (f) || (iszfs () && _ishidden_zfs (f))
125
+ else # General UNIX
126
+ _ishidden (f:: AbstractString ) = _ishidden_unix (f) || (iszfs () && _ishidden_zfs (f))
115
127
end
116
128
elseif Sys. iswindows ()
117
129
# https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants
@@ -137,5 +149,5 @@ function ishidden(f::AbstractString)
137
149
end
138
150
139
151
140
- end
152
+ end # end module
141
153
0 commit comments