Skip to content

Commit 904aa1d

Browse files
committed
Add fallback search paths for Unix utilities
On macOS, some projects manipulate PATH and become unable to find chown due to the recent changes. To protect against this and similar future changes, add a set of default search paths for the typical Unix tool locations of /usr/{bin,sbin} and /{bin,sbin}, attempting to follow the usual relative orderings on each platform.
1 parent 1ed8aaa commit 904aa1d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Sources/SWBCore/Settings/Settings.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,44 @@ extension WorkspaceContext {
10321032
}
10331033
}
10341034

1035+
// Add the system-level bin directories common to most Unix-like platforms if they weren't already present.
1036+
// This is not an exhaustive list that exactly matches the platform defaults, but generally aims to follow the same relative ordering.
1037+
switch core.hostOperatingSystem {
1038+
case .macOS:
1039+
paths.append(contentsOf: [
1040+
.root.join("usr").join("bin"),
1041+
.root.join("bin"),
1042+
.root.join("usr").join("sbin"),
1043+
.root.join("sbin"),
1044+
])
1045+
case .linux:
1046+
paths.append(contentsOf: [
1047+
.root.join("usr").join("sbin"),
1048+
.root.join("usr").join("bin"),
1049+
.root.join("sbin"),
1050+
.root.join("bin"),
1051+
])
1052+
case .freebsd:
1053+
paths.append(contentsOf: [
1054+
.root.join("sbin"),
1055+
.root.join("bin"),
1056+
.root.join("usr").join("sbin"),
1057+
.root.join("usr").join("bin"),
1058+
])
1059+
case .openbsd:
1060+
paths.append(contentsOf: [
1061+
.root.join("bin"),
1062+
.root.join("sbin"),
1063+
.root.join("usr").join("bin"),
1064+
.root.join("usr").join("sbin"),
1065+
])
1066+
case .android:
1067+
// FIXME: where are system utilities on Android?
1068+
break
1069+
case .iOS, .tvOS, .watchOS, .visionOS, .windows, .unknown:
1070+
break
1071+
}
1072+
10351073
return StackedSearchPath(paths: [Path](paths), fs: fs)
10361074
}
10371075
}

0 commit comments

Comments
 (0)