Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor FileSystem handling (fix absolute paths on Windows) #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BlazingTwist
Copy link
Contributor

@BlazingTwist BlazingTwist commented May 13, 2024

I noticed that while G works great, .G does not.
Example: "C:\abs\file.txt" :& G \ "_2"+ 0 .G (which should copy the file content into C:\abs\file.txt_2)
instead results in

io_err at .G: unable to use resource C:\tools\Aya\bin_v4_rc1\C:\abs\file.txt_2. Invalid path
   in .G .. }

So I had a look at all the uses of AyaPrefs.getWorkingDir() and updated those.

Tests

.# Windows Tests
"C:/abs/test.txt" :& G \ "_2"+ 0 .G       .# correctly copies from C:/abs/test.txt     to C:/abs/test.txt_2        preserving \r\n
"test.txt"        :& G \ "_2"+ 0 .G       .# correctly copies from <workDir>/test.txt  to <workDir>/test.txt_2 preserving \r\n
"/test.txt"       :& G \ "_2"+ 0 .G       .# behaves identical to "test.txt" on Windows (good)

.# WSL Ubuntu Tests
"C:/abs/test.txt"     :& G \ "_2"+ 0 .G   .# io_err at G: unable to use resource /mnt/c/tools/Aya/bin_v4_rc1/C:/abs/test.txt (good)
"test.txt"            :& G \ "_2"+ 0 .G   .# correctly copies from <workDir>/test.txt  to <workDir>/test.txt_2
"/mnt/c/abs/test.txt" :& G \ "_3"+ 0 .G   .# correctly copies from C:/abs/test.txt     to C:/abs/test.txt_2

:{sys.file_exists} also behaves as expected.
I did not test SaveGraphicsInstruction, Plots and File-Deletion (seems reasonable to assume that these will operate correctly)

br.close();
return sb.toString();
public static String readAllText(File file) throws IOException {
return new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); // in Java 11 you can also do Files.readString(Path)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is not exactly equivalent to the previous implementation, as \r\n is not trimmed to \n.
I think this is preferable when working with binary files. (Unless there's an operator for reading binary files that I missed?)

@@ -66,7 +66,7 @@
public class Ops {

public static final Random RAND = new Random((new Date()).getTime());
public static final Pattern PATTERN_URL = Pattern.compile("http:\\/\\/.*|https:\\/\\/.*");
public static final Pattern PATTERN_URL = Pattern.compile("https?://.*");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is kinda off-topic. But I figured it was reasonable enough.

@@ -107,23 +107,7 @@ public static boolean setAyaDir(String dir) {
return false;
}
}

public static ArrayList<String> listFilesForWorkingDir() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these methods were unused

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant