Skip to content

Commit

Permalink
fix path parse issue
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalgust committed Mar 3, 2024
1 parent 6bdda66 commit c9ac707
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
10 changes: 4 additions & 6 deletions minijvm/c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ int main(int argc, char **argv) {
c8 *bootclasspath = NULL;
c8 *classpath = NULL;
c8 *main_name = NULL;
s32 print_version = 0;
s32 main_set = 0;
ArrayList *java_para = arraylist_create(0);
s32 jdwp = 0;
Expand All @@ -42,7 +41,7 @@ int main(int argc, char **argv) {
#endif
s32 dpos = utf8_last_indexof_c(startup_dir, "/");
if (dpos > 0)utf8_substring(startup_dir, 0, dpos);
utf8_append_c(startup_dir, "/");
if (utf8_char_at(startup_dir, startup_dir->length - 1) != '/')utf8_append_c(startup_dir, "/");
#if _JVM_DEBUG_LOG_LEVEL > 0
jvm_printf("App dir:%s\n", utf8_cstr(startup_dir));
#endif
Expand All @@ -51,7 +50,7 @@ int main(int argc, char **argv) {
utf8_append(bootcp, startup_dir);
utf8_append_c(bootcp, "../lib/minijvm_rt.jar");
bootclasspath = (c8 *) utf8_cstr(bootcp);
jdwp = 1; // 0:disable java debug , 1:enable java debug and disable jit
jdwp = 0; // 0:disable java debug , 1:enable java debug and disable jit

//test for graphics
utf8_append(cp, startup_dir);
Expand Down Expand Up @@ -120,7 +119,7 @@ int main(int argc, char **argv) {
// classpath = (c8 *) utf8_cstr(cp);
// main_name = "org.luaj.vm2.lib.jme.TestLuaJ";

}
}//default args

// mini_jvm -Xmx16M -bootclasspath ../lib/minijvm_rt.jar -cp ../libex/minijvm_test.jar;./ test/Foo1 999
if (argc > 1) {
Expand All @@ -129,8 +128,7 @@ int main(int argc, char **argv) {
if (strcmp(argv[i], "-bootclasspath") == 0) {
bootclasspath = argv[i + 1];
i++;
} else if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
print_version = 1;
} else if (strcmp(argv[i], "-version") == 0) {
classpath = NULL;
main_name = "org.mini.vm.PrintVersion";
i++;
Expand Down
2 changes: 1 addition & 1 deletion minijvm/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>io.github.digitalgust</groupId>
<artifactId>minijvm_rt</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
<version>1.1.4</version>
<version>1.1.5</version>
<description>miniJVM runtime library</description>
<url>https://github.com/digitalgust/miniJVM</url>

Expand Down
26 changes: 16 additions & 10 deletions minijvm/java/src/main/java/org/mini/fs/FileSystemImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,19 @@ public String normalize(String path) {
while (path.indexOf(ds) >= 0) {
path = path.replace(ds, ss);
}
path = path.replace(getSeparator() + PARENT_DIR + getSeparator(), "\uffff\uffff\uffff");
path = path.replace(getSeparator() + CUR_DIR + getSeparator(), getSeparator() + ""); //remove all "./" to ""
path = path.replace("\uffff\uffff\uffff", getSeparator() + PARENT_DIR + getSeparator());

if (path.endsWith(getSeparator() + CUR_DIR)) { // "/tmp/abc/." -> "/tmp/abc/./"
path = path + getSeparator();
}
// https://github.com/digitalgust/miniJVM/issues/31
// "/tmp/abc/./" -> "/tmp/abc"
while (path.indexOf(getSeparator() + CUR_DIR + getSeparator()) >= 0) {
path = path.replace(getSeparator() + CUR_DIR + getSeparator(), getSeparator() + "");
}

// path = path.replace(getSeparator() + PARENT_DIR + getSeparator(), "\uffff\uffff\uffff");
// path = path.replace(getSeparator() + CUR_DIR + getSeparator(), getSeparator() + ""); //remove all "./" to ""
// path = path.replace("\uffff\uffff\uffff", getSeparator() + PARENT_DIR + getSeparator());
if (path.length() > 1 && path.lastIndexOf(getSeparator()) == path.length() - 1) {//remove last char if it's '/'
path = path.substring(0, path.length() - 1);
}
Expand All @@ -70,15 +80,11 @@ protected String getFullPath(String path) {
if (!isAbsolute(path)) {
path = parent + getSeparator() + path; // replace "/tmp/abc/../a.txt" to "/tmp/a.txt"
}
path = removeParentTag(path);
// MUST remove current dir first /./ ,like "/a/./../b" -> "/a/../b"
path = normalize(path);
if (path.endsWith(getSeparator() + CUR_DIR)) { // "/tmp/abc/." -> "/tmp/abc/./"
path = path + getSeparator();
}
// https://github.com/digitalgust/miniJVM/issues/31
// "/tmp/abc/./" -> "/tmp/abc"
path = path.replace(getSeparator() + CUR_DIR + getSeparator(), getSeparator() + "");

//remove parent tag /../
path = removeParentTag(path);
return path;
}

Expand Down

0 comments on commit c9ac707

Please sign in to comment.