Browse code

BM-14176 Fix: use java.io to prevent canonical filename conversion

Thomas Fricker authored on 04/02/2019 13:33:14
Showing 1 changed files
... ...
@@ -18,17 +18,15 @@
18 18
  */
19 19
 package net.bluemind.node.server.handlers;
20 20
 
21
+import java.io.File;
22
+
21 23
 import org.slf4j.Logger;
22 24
 import org.slf4j.LoggerFactory;
23 25
 import org.vertx.java.core.Handler;
24
-import org.vertx.java.core.file.FileProps;
25
-import org.vertx.java.core.file.FileSystem;
26 26
 import org.vertx.java.core.http.HttpServerRequest;
27 27
 import org.vertx.java.core.json.JsonArray;
28 28
 import org.vertx.java.core.json.JsonObject;
29 29
 
30
-import net.bluemind.lib.vertx.VertxPlatform;
31
-
32 30
 public abstract class AbstractListFiles implements Handler<HttpServerRequest> {
33 31
 
34 32
 	@SuppressWarnings("unused")
... ...
@@ -39,24 +37,21 @@ public abstract class AbstractListFiles implements Handler<HttpServerRequest> {
39 37
 	}
40 38
 
41 39
 	protected void handle(String path, String extension, final HttpServerRequest req) {
42
-		FileSystem fs = VertxPlatform.getVertx().fileSystem();
43 40
 		// this does not list content if path is a directory..
44 41
 		JsonObject jso = new JsonObject();
45 42
 		JsonArray descs = new JsonArray();
46 43
 		jso.putArray("descriptions", descs);
47 44
 		try {
48
-			FileProps asked = fs.lpropsSync(path);
45
+			File asked = new File(path);
49 46
 			if (asked.isDirectory()) {
50
-				String[] content = fs.readDirSync(path);
47
+				String[] content = asked.list();
51 48
 				for (String p : content) {
52
-					if (extension == null) {
53
-						descs.addObject(json(p, fs.lpropsSync(p)));
54
-					} else if (p.endsWith(extension)) {
55
-						descs.addObject(json(p, fs.lpropsSync(p)));
49
+					if (extension == null || p.endsWith(extension)) {
50
+						descs.addObject(json(new File(asked, p)));
56 51
 					}
57 52
 				}
58 53
 			} else {
59
-				descs.addObject(json(path, asked));
54
+				descs.addObject(json(asked));
60 55
 			}
61 56
 			req.response().end(jso.encode());
62 57
 		} catch (Exception t) {
... ...
@@ -64,12 +59,12 @@ public abstract class AbstractListFiles implements Handler<HttpServerRequest> {
64 59
 		}
65 60
 	}
66 61
 
67
-	private JsonObject json(String path, FileProps fp) {
62
+	private JsonObject json(File fp) {
68 63
 		JsonObject fdo = new JsonObject();
69
-		fdo.putString("path", path);
64
+		fdo.putString("path", fp.getAbsolutePath());
70 65
 		fdo.putBoolean("dir", fp.isDirectory());
71 66
 		if (!fp.isDirectory()) {
72
-			fdo.putNumber("size", fp.size());
67
+			fdo.putNumber("size", fp.length());
73 68
 		}
74 69
 		return fdo;
75 70
 	}