Skip to content

Commit

Permalink
Small fixes [release]
Browse files Browse the repository at this point in the history
  • Loading branch information
crschnick committed Mar 21, 2023
1 parent 1f9d5ab commit b881e54
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 33 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public static String normalizeDirectoryPath(OpenFileSystemModel model, String pa
.getShellDialect()
.normalizeDirectory(shell.get(), path)
.readOrThrow();

if (!model.getFileSystem().directoryExists(normalized)) {
throw new IllegalArgumentException(String.format("Directory %s does not exist", normalized));
}

return FileNames.toDirectory(normalized);
}

Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/io/xpipe/core/process/CommandControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ default void execute() throws Exception {
}
}

default boolean executeAndCheck() throws Exception {
try (var c = start()) {
return c.discardAndCheckExit();
}
}

ShellControl getParent();

InputStream startExternalStdout() throws Exception;
Expand Down
17 changes: 0 additions & 17 deletions core/src/main/java/io/xpipe/core/process/OsType.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public static OsType getLocal() {

String getTempDirectory(ShellControl pc) throws Exception;

String normalizeFileName(String file);

Map<String, String> getProperties(ShellControl pc) throws Exception;

String determineOperatingSystemName(ShellControl pc) throws Exception;
Expand All @@ -51,11 +49,6 @@ public String getTempDirectory(ShellControl pc) throws Exception {
return pc.executeStringSimpleCommand(pc.getShellDialect().getPrintEnvironmentVariableCommand("TEMP"));
}

@Override
public String normalizeFileName(String file) {
return String.join("\\", file.split("[\\\\/]+"));
}

@Override
public Map<String, String> getProperties(ShellControl pc) throws Exception {
try (CommandControl c = pc.command("systeminfo").start()) {
Expand Down Expand Up @@ -84,11 +77,6 @@ public String getTempDirectory(ShellControl pc) throws Exception {
return "/tmp/";
}

@Override
public String normalizeFileName(String file) {
return String.join("/", file.split("[\\\\/]+"));
}

@Override
public String getName() {
return "Linux";
Expand Down Expand Up @@ -154,11 +142,6 @@ public String getTempDirectory(ShellControl pc) throws Exception {
return found;
}

@Override
public String normalizeFileName(String file) {
return String.join("/", file.split("[\\\\/]+"));
}

@Override
public String getName() {
return "Mac";
Expand Down
5 changes: 1 addition & 4 deletions core/src/main/java/io/xpipe/core/process/ShellDialect.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import io.xpipe.core.charsetter.NewLine;
import io.xpipe.core.charsetter.StreamCharset;
import io.xpipe.core.store.FileSystem;

import java.nio.charset.Charset;
Expand All @@ -14,9 +13,7 @@
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
public interface ShellDialect {

default StreamCharset getTextFileCharset(ShellControl sc) {
return StreamCharset.get(sc.getCharset(), false);
}
CommandControl directoryExists(ShellControl shellControl, String directory);

CommandControl normalizeDirectory(ShellControl shellControl, String directory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public void init(ModuleLayer layer) {

CMD = byName("cmd");
POWERSHELL = byName("powershell");
SH = byName("sh");
DASH = byName("dash");
BASH = byName("bash");
ZSH = byName("zsh");
SH = byName("sh");
}

@Override
Expand Down
20 changes: 11 additions & 9 deletions core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public List<String> listRoots() throws Exception {
}

@Override
public boolean isDirectory(String file) throws Exception{return true;}
public boolean directoryExists(String file) throws Exception{
return shellControl.getShellDialect().directoryExists(shellControl, file).executeAndCheck();
}

@Override
public Stream<FileEntry> listFiles(String file) throws Exception {
Expand All @@ -57,21 +59,21 @@ public FileSystem open() throws Exception {
@Override
public InputStream openInput(String file) throws Exception {
return shellControl.command(proc ->
proc.getShellDialect().getFileReadCommand(proc.getOsType().normalizeFileName(file)))
proc.getShellDialect().getFileReadCommand(file))
.startExternalStdout();
}

@Override
public OutputStream openOutput(String file) throws Exception {
return shellControl.getShellDialect()
.createStreamFileWriteCommand(shellControl, shellControl.getOsType().normalizeFileName(file))
.createStreamFileWriteCommand(shellControl, file)
.startExternalStdin();
}

@Override
public boolean exists(String file) throws Exception {
try (var pc = shellControl.command(proc -> proc.getShellDialect()
.getFileExistsCommand(proc.getOsType().normalizeFileName(file))).complex()
.getFileExistsCommand(file)).complex()
.start()) {
return pc.discardAndCheckExit();
}
Expand All @@ -80,7 +82,7 @@ public boolean exists(String file) throws Exception {
@Override
public void delete(String file) throws Exception {
try (var pc = shellControl.command(proc -> proc.getShellDialect()
.getFileDeleteCommand(proc.getOsType().normalizeFileName(file))).complex()
.getFileDeleteCommand(file)).complex()
.start()) {
pc.discardOrThrow();
}
Expand All @@ -89,7 +91,7 @@ public void delete(String file) throws Exception {
@Override
public void copy(String file, String newFile) throws Exception {
try (var pc = shellControl.command(proc -> proc.getShellDialect()
.getFileCopyCommand(proc.getOsType().normalizeFileName(file), proc.getOsType().normalizeFileName(newFile))).complex()
.getFileCopyCommand(file, newFile)).complex()
.start()) {
pc.discardOrThrow();
}
Expand All @@ -98,7 +100,7 @@ public void copy(String file, String newFile) throws Exception {
@Override
public void move(String file, String newFile) throws Exception {
try (var pc = shellControl.command(proc -> proc.getShellDialect()
.getFileMoveCommand(proc.getOsType().normalizeFileName(file), proc.getOsType().normalizeFileName(newFile))).complex()
.getFileMoveCommand(file, newFile)).complex()
.start()) {
pc.discardOrThrow();
}
Expand All @@ -107,7 +109,7 @@ public void move(String file, String newFile) throws Exception {
@Override
public boolean mkdirs(String file) throws Exception {
try (var pc = shellControl.command(proc -> proc.getShellDialect()
.getMkdirsCommand(proc.getOsType().normalizeFileName(file))).complex()
.getMkdirsCommand(file)).complex()
.start()) {
return pc.discardAndCheckExit();
}
Expand All @@ -116,7 +118,7 @@ public boolean mkdirs(String file) throws Exception {
@Override
public void touch(String file) throws Exception {
try (var pc = shellControl.command(proc -> proc.getShellDialect()
.getFileTouchCommand(proc.getOsType().normalizeFileName(file))).complex()
.getFileTouchCommand(file)).complex()
.start()) {
pc.discardOrThrow();
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/io/xpipe/core/store/FileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public FileEntry(

void touch(String file) throws Exception;

boolean isDirectory(String file) throws Exception;
boolean directoryExists(String file) throws Exception;

Stream<FileEntry> listFiles(String file) throws Exception;

Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.16
0.5.17

0 comments on commit b881e54

Please sign in to comment.