Various fixes

This commit is contained in:
crschnick committed 2026-09-26 10:17:57 +00:00
1 parent 52135eb2b6
commit 08d0b297f5
8 files changed
+28 -32

No files matched your search

@@ -28,7 +28,7 @@ public class TerminalExternalLaunchExchange extends BeaconInterface<TerminalExte
@Override
public Object handle(HttpExchange exchange, Request msg) throws BeaconClientException, BeaconServerException {
var found = DataStorageQuery.queryUserInput(msg.getConnection());
var found = DataStorageQuery.queryEntry(msg.getConnection());
if (found.isEmpty()) {
throw new BeaconClientException("No connection found for input " + msg.getConnection());
}
@@ -133,7 +133,7 @@ public interface McpToolHandler
}
public DataStoreEntryRef<?> getDataStoreRef(String name) throws BeaconClientException {
var found = DataStorageQuery.queryUserInput(name);
var found = DataStorageQuery.queryEntry(name);
if (found.isEmpty()) {
throw new BeaconClientException("No connection found for input " + name);
}
@@ -157,7 +157,7 @@ public final class McpTools {
.tool(tool)
.callHandler(McpToolHandler.of((req) -> {
var filter = req.getStringArgument("filter");
var entries = DataStorageQuery.queryUserInput(filter);
var entries = DataStorageQuery.queryEntry(filter);
var list = new ArrayList<ConnectionResource>();
for (var e : entries) {
@@ -54,7 +54,7 @@ public interface BrowserFileInput {
}
var userOwned = info.getUid() != null
&& sc.view().getPasswdFile().getUidForUser(sc.view().user()) == info.getUid()
&& info.getUid().equals(sc.view().getPasswdFile().getUidForUserIfPresent(sc.view().user()).orElse(null))
|| info.getUser() != null && sc.view().user().equals(info.getUser());
var userWrite = info.getPermissions().charAt(0) == 'r';
if (userOwned && userWrite) {
@@ -229,7 +229,7 @@ class BrowserFileListNameCell extends TableCell<BrowserEntry, String> {
.resolved()
.getPath();
var currentPath = fileList.getFileSystemModel().getCurrentDirectory();
var shownTarget = currentPath != null && target.startsWith(currentPath.getPath()) ?
var shownTarget = currentPath != null && target.startsWith(currentPath.getPath().toDirectory()) ?
"./" + target.relativize(currentPath.getPath()) : target;
fileName = i.getFileName() + " -> " + shownTarget;
} else {
@@ -60,7 +60,7 @@ public interface BrowserFileOutput {
}
var userOwned = info.getUid() != null
&& sc.view().getPasswdFile().getUidForUser(sc.view().user()) == info.getUid()
&& info.getUid().equals(sc.view().getPasswdFile().getUidForUserIfPresent(sc.view().user()).orElse(null))
|| info.getUser() != null && sc.view().user().equals(info.getUser());
var userWrite = info.getPermissions().charAt(1) == 'w';
if (userOwned && userWrite) {
@@ -2,30 +2,25 @@ package io.xpipe.app.storage;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
public class DataStorageQuery {
public static List<DataStoreEntry> queryUserInput(String input) {
var connectionFilter = input != null && !input.isEmpty() && !input.equals("*") && !input.equals("**")
? "**" + input + "**"
: "**";
var found = queryEntry("**", connectionFilter, "*");
public static List<DataStoreEntry> queryEntry(String globInput) {
var found = queryEntry("**", globInput, "*");
if (found.size() > 1) {
var narrowPath = found.stream()
.filter(dataStoreEntry -> DataStorage.get()
.getStorePath(dataStoreEntry)
.toString()
.equalsIgnoreCase(input))
.equalsIgnoreCase(globInput))
.toList();
if (narrowPath.size() >= 1) {
return narrowPath;
}
var narrowName = found.stream()
.filter(dataStoreEntry -> dataStoreEntry.getName().equalsIgnoreCase(input))
.filter(dataStoreEntry -> dataStoreEntry.getName().equalsIgnoreCase(globInput))
.toList();
if (narrowName.size() >= 1) {
return narrowName;
@@ -34,12 +29,12 @@ public class DataStorageQuery {
return found;
}
public static List<DataStoreCategory> queryCategory(String categoryFilter) {
public static List<DataStoreCategory> queryCategory(String categoryGlobFilter) {
if (DataStorage.get() == null) {
return List.of();
}
var catMatcher = compilePattern(categoryFilter);
var catMatcher = compileSearchPattern(categoryGlobFilter);
List<DataStoreCategory> found = new ArrayList<>();
for (DataStoreCategory cat : DataStorage.get().getStoreCategories()) {
@@ -53,14 +48,14 @@ public class DataStorageQuery {
return found;
}
public static List<DataStoreEntry> queryEntry(String categoryFilter, String connectionFilter, String typeFilter) {
public static List<DataStoreEntry> queryEntry(String categoryGlobFilter, String connectionGlobFilter, String typeGlobFilter) {
if (DataStorage.get() == null) {
return List.of();
}
var catMatcher = compilePattern(categoryFilter);
var conMatcher = compilePattern(connectionFilter);
var typeMatcher = compilePattern(typeFilter);
var catMatcher = compileSearchPattern(categoryGlobFilter);
var conMatcher = compileSearchPattern(connectionGlobFilter);
var typeMatcher = compileSearchPattern(typeGlobFilter);
List<DataStoreEntry> found = new ArrayList<>();
for (DataStoreEntry storeEntry : DataStorage.get().getStoreEntries()) {
@@ -96,14 +91,14 @@ public class DataStorageQuery {
return found;
}
public static String toRegex(String pattern) {
pattern = pattern.replaceAll("\\*\\*", "#");
public static String toRegex(String globPattern) {
globPattern = globPattern.replaceAll("\\*\\*", "#");
// https://stackoverflow.com/a/17369948/6477761
StringBuilder sb = new StringBuilder(pattern.length());
StringBuilder sb = new StringBuilder(globPattern.length());
int inGroup = 0;
int inClass = 0;
int firstIndexInClass = -1;
char[] arr = pattern.toCharArray();
char[] arr = globPattern.toCharArray();
for (int i = 0; i < arr.length; i++) {
char ch = arr[i];
switch (ch) {
@@ -199,11 +194,16 @@ public class DataStorageQuery {
return sb.toString();
}
private static Pattern compilePattern(String pattern) {
private static Pattern compileSearchPattern(String globPattern) {
var complexGlob = !globPattern.isEmpty() && !globPattern.equals("*") && !globPattern.equals("**");
if (!complexGlob) {
return Pattern.compile(toRegex(globPattern));
}
try {
return Pattern.compile(toRegex(pattern.toLowerCase()));
return Pattern.compile(toRegex("**" + globPattern.toLowerCase() + "**"));
} catch (Throwable e) {
return Pattern.compile(Pattern.quote(pattern));
return Pattern.compile(Pattern.quote(globPattern));
}
}
}
@@ -30,10 +30,6 @@ public class PasswdFile {
return found != null ? Optional.of(found) : Optional.empty();
}
public int getUidForUser(String name) {
return getUidForUserIfPresent(name).orElse(0);
}
private void loadUsers(ShellControl sc) throws Exception {
if (sc.getOsType() == OsType.WINDOWS || sc.getOsType() == OsType.MACOS) {
return;