From c9ac7077319d6ec4ded7e15c06c4f6c445955986 Mon Sep 17 00:00:00 2001 From: Gust Date: Sun, 3 Mar 2024 11:00:11 +0800 Subject: [PATCH] fix path parse issue --- minijvm/c/main.c | 10 +++---- minijvm/java/pom.xml | 2 +- .../main/java/org/mini/fs/FileSystemImpl.java | 26 ++++++++++++------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/minijvm/c/main.c b/minijvm/c/main.c index 61a3b684..37e20218 100644 --- a/minijvm/c/main.c +++ b/minijvm/c/main.c @@ -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; @@ -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 @@ -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); @@ -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) { @@ -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++; diff --git a/minijvm/java/pom.xml b/minijvm/java/pom.xml index 51473c80..ffbd45a2 100755 --- a/minijvm/java/pom.xml +++ b/minijvm/java/pom.xml @@ -8,7 +8,7 @@ io.github.digitalgust minijvm_rt ${project.groupId}:${project.artifactId} - 1.1.4 + 1.1.5 miniJVM runtime library https://github.com/digitalgust/miniJVM diff --git a/minijvm/java/src/main/java/org/mini/fs/FileSystemImpl.java b/minijvm/java/src/main/java/org/mini/fs/FileSystemImpl.java index 083ebd85..e9dba97b 100644 --- a/minijvm/java/src/main/java/org/mini/fs/FileSystemImpl.java +++ b/minijvm/java/src/main/java/org/mini/fs/FileSystemImpl.java @@ -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); } @@ -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; }