From 18b768b32f3703f14ea22ed509c014332736fa1a Mon Sep 17 00:00:00 2001 From: Paul Fulham Date: Sat, 21 Nov 2020 22:00:05 -0800 Subject: [PATCH] Fix upload handling --- .../content/schematics/ServerSchematicLoader.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/schematics/ServerSchematicLoader.java b/src/main/java/com/simibubi/create/content/schematics/ServerSchematicLoader.java index 5c2ee7466..743cc5a3b 100644 --- a/src/main/java/com/simibubi/create/content/schematics/ServerSchematicLoader.java +++ b/src/main/java/com/simibubi/create/content/schematics/ServerSchematicLoader.java @@ -101,10 +101,10 @@ public class ServerSchematicLoader { return; } - Path schematicPath = Paths.get(getSchematicPath()).toAbsolutePath(); + Path playerSchematicsPath = Paths.get(getSchematicPath(), player.getGameProfile().getName()).toAbsolutePath(); - Path uploadPath = schematicPath.resolve(playerSchematicId).normalize(); - if (!uploadPath.startsWith(schematicPath)) { + Path uploadPath = playerSchematicsPath.resolve(schematic).normalize(); + if (!uploadPath.startsWith(playerSchematicsPath)) { Create.logger.warn("Attempted Schematic Upload with directory escape: {}", playerSchematicId); return; } @@ -123,6 +123,9 @@ public class ServerSchematicLoader { if (table == null) return; + // Delete schematic with same name + Files.deleteIfExists(uploadPath); + // Too many Schematics long count; try (Stream list = Files.list(Paths.get(playerPath))) { @@ -295,6 +298,9 @@ public class ServerSchematicLoader { return; try { + // Delete schematic with same name + Files.deleteIfExists(path); + // Too many Schematics long count; try (Stream list = Files.list(Paths.get(playerPath))) {