MCPcopy
hub / github.com/xpipe-io/xpipe / Unix

Class Unix

app/src/main/java/io/xpipe/app/process/OsFileSystem.java:109–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107 }
108
109 class Unix implements OsFileSystem {
110
111 public boolean isProbableFilePath(String s) {
112 return s.startsWith("/");
113 }
114
115 @Override
116 public String makeFileSystemCompatible(String name) {
117 // Technically the backslash is supported, but it causes all kinds of troubles, so we also exclude it
118 return name.replaceAll("[/\\\\]", "_").replaceAll("\0", "");
119 }
120
121 @Override
122 public String getUserHomeDirectory(ShellControl pc) throws Exception {
123 var r = pc.view().getEnvironmentVariable("HOME");
124 if (r.isEmpty()) {
125 var user = pc.view().user();
126 var eval = pc.command("eval echo ~" + user).readStdoutIfPossible();
127 if (eval.isPresent() && !eval.get().isBlank()) {
128 return eval.get();
129 }
130
131 if (user.equals("root")) {
132 return "/root";
133 } else {
134 return "/home/" + user;
135 }
136 } else {
137 return r.get();
138 }
139 }
140
141 @Override
142 public String getFileSystemSeparator() {
143 return "/";
144 }
145
146 @Override
147 public boolean hasMultipleRoots() {
148 return false;
149 }
150 }
151
152 final class MacOs implements OsFileSystem {
153

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…