mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-09-26 18:35:43 +00:00
Fix file system compat method for windows
This commit is contained in:
@@ -5,6 +5,8 @@ import io.xpipe.core.OsType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public interface OsFileSystem {
|
||||
@@ -30,14 +32,21 @@ public interface OsFileSystem {
|
||||
|
||||
default FilePath makeFileSystemCompatible(FilePath name) {
|
||||
var split = name.split();
|
||||
var needsReplacement = split.stream().anyMatch(s -> !s.equals(makeFileSystemCompatible(s)));
|
||||
var needsReplacement = split.stream().skip(hasMultipleRoots() ? 1 : 0).anyMatch(s -> !s.equals(makeFileSystemCompatible(s)));
|
||||
if (!needsReplacement) {
|
||||
return name;
|
||||
}
|
||||
|
||||
var p = Pattern.compile("[^/\\\\]+");
|
||||
var m = p.matcher(name.toString());
|
||||
var replaced = m.replaceAll(matchResult -> makeFileSystemCompatible(matchResult.group()));
|
||||
var first = new AtomicBoolean(true);
|
||||
var replaced = m.replaceAll(matchResult -> {
|
||||
if (first.getAndSet(false) && hasMultipleRoots()) {
|
||||
return matchResult.group();
|
||||
}
|
||||
|
||||
return makeFileSystemCompatible(matchResult.group());
|
||||
});
|
||||
return FilePath.of(replaced);
|
||||
}
|
||||
|
||||
@@ -49,6 +58,8 @@ public interface OsFileSystem {
|
||||
|
||||
String getFileSystemSeparator();
|
||||
|
||||
boolean hasMultipleRoots();
|
||||
|
||||
final class Windows implements OsFileSystem {
|
||||
|
||||
@Override
|
||||
@@ -83,6 +94,11 @@ public interface OsFileSystem {
|
||||
public String getFileSystemSeparator() {
|
||||
return "\\";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMultipleRoots() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class Unix implements OsFileSystem {
|
||||
@@ -134,6 +150,11 @@ public interface OsFileSystem {
|
||||
public String getFileSystemSeparator() {
|
||||
return "/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMultipleRoots() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final class MacOs implements OsFileSystem {
|
||||
@@ -169,5 +190,10 @@ public interface OsFileSystem {
|
||||
public String getFileSystemSeparator() {
|
||||
return "/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMultipleRoots() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user