Skip to content

Commit 1860472

Browse files
Drop /Applications, /Library and /Volumes; make the visibility tests portable
The node table is the Filesystem Hierarchy Standard's paths plus the macOS directories that carry FHS content under another name. /Applications, /Library and /Volumes are none of those: they are macOS's own, have no counterpart in the FHS, and the Finder shows them already, so offering to manage them was offering something this project has no business managing. Removing them from the table removes them from the menu, the preference pane and `fhsctl vis` at once, since all three read that one list. The visibility tests no longer assume a directory exists. /opt is the instructive case: it is not part of a stock macOS install at all - Homebrew creates it - so asserting it exists and is changeable makes `make check` fail on any machine without Homebrew, for a reason unrelated to this code. CI passes today only because GitHub's macOS images ship Homebrew preinstalled. The three changeable nodes are now asserted conditionally, which keeps the property worth pinning - a node that is present classifies as measured, so an OS change is still caught - without testing the runner's image.
1 parent 9bd2270 commit 1860472

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/visibility/fhs_visibility.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@
2929
* Alphabetical, as the Finder and the menu present them - not grouped by
3030
* origin, because a user looking for a directory knows its name and not
3131
* whether macOS or this layer put it there.
32+
*
33+
* The list is the Filesystem Hierarchy Standard's, plus the macOS directories
34+
* that carry FHS content under another name. /Applications, /Library and
35+
* /Volumes are deliberately absent: they are macOS's own, have no counterpart
36+
* in the FHS, and the Finder shows them already, so presenting them here would
37+
* be offering to manage directories this project has no business managing.
3238
*/
3339
const struct fhs_node fhs_root_nodes[] = {
34-
{ "/Applications", false },
3540
{ "/bin", false },
3641
{ "/boot", true },
3742
{ "/cores", false },
3843
{ "/dev", false },
3944
{ "/etc", false },
4045
{ "/home", true },
41-
{ "/Library", false },
4246
{ "/media", true },
4347
{ "/mnt", true },
4448
{ "/opt", false },
@@ -50,7 +54,6 @@ const struct fhs_node fhs_root_nodes[] = {
5054
{ "/tmp", false },
5155
{ "/usr", false },
5256
{ "/var", false },
53-
{ "/Volumes", false },
5457
};
5558

5659
const size_t fhs_root_node_count =

tests/test_visibility.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ main(void)
8484
check("Linux-only nodes are marked", fhs_node_find("/media")->linux_only);
8585
check("native nodes are not", !fhs_node_find("/usr")->linux_only);
8686

87+
/* macOS-only directories with no FHS counterpart are not presented. */
88+
check("/Applications is not a node", fhs_node_find("/Applications") == NULL);
89+
check("/Library is not a node", fhs_node_find("/Library") == NULL);
90+
check("/Volumes is not a node", fhs_node_find("/Volumes") == NULL);
91+
8792
/* Every lock value must have a reason; only CHANGEABLE has none. */
8893
check("CHANGEABLE has no reason", fhs_vis_lock_reason(FHS_VIS_CHANGEABLE) == NULL);
8994
check("ABSENT has a reason", fhs_vis_lock_reason(FHS_VIS_ABSENT) != NULL);
@@ -164,6 +169,8 @@ main(void)
164169
rmdir(TEST_SCRATCH);
165170

166171
/* --- classification of the real root, read-only --------------------- */
172+
static const char *const changeable[] = { "/opt", "/cores", "/Volumes" };
173+
167174
printf("\n (the following read real system paths; none are modified)\n");
168175

169176
check_lock("/bin", FHS_VIS_SIP, "SIP");
@@ -182,9 +189,22 @@ main(void)
182189
check_lock("/home", FHS_VIS_ABSENT, "absent");
183190
check_lock("/private", FHS_VIS_PROTECTED, "protected");
184191
check_lock("/dev", FHS_VIS_UNSUPPORTED, "unsupported");
185-
check_lock("/opt", FHS_VIS_CHANGEABLE, "changeable");
186-
check_lock("/cores", FHS_VIS_CHANGEABLE, "changeable");
187-
check_lock("/Volumes", FHS_VIS_CHANGEABLE, "changeable");
192+
/*
193+
* The changeable nodes, asserted only where they exist.
194+
*
195+
* /opt is the instructive one: it is not part of a stock macOS install at
196+
* all - Homebrew creates it - so hard-coding "exists and is changeable"
197+
* makes the test suite fail on a machine without Homebrew, for a reason
198+
* that has nothing to do with this code. The property worth pinning is
199+
* that a node which *is* present classifies as measured, so an OS change
200+
* is still caught.
201+
*/
202+
for (size_t i = 0; i < sizeof(changeable) / sizeof(changeable[0]); i++) {
203+
if (fhs_vis_status(changeable[i], &st) == 0 && st.exists)
204+
check_lock(changeable[i], FHS_VIS_CHANGEABLE, "changeable");
205+
else
206+
check_lock(changeable[i], FHS_VIS_ABSENT, "absent");
207+
}
188208

189209
/* /dev is the case the verification logic exists for. */
190210
check("/dev is a mount point",

0 commit comments

Comments
 (0)