@@ -20,13 +20,14 @@ public class MrPackInstaller {
2020 private final Path destinationOldModified ;
2121 private final InstanceInfo currentInstanceData ;
2222 private final Set <String > whitelistedDomains ;
23+ private final HashSet <String > nonOverwritablePaths ;
2324 @ Nullable
2425 private String newLauncher ;
2526 @ Nullable
2627 private Installer installer ;
2728 private boolean forceSystemClasspath = false ;
2829
29- public MrPackInstaller (Path source , ModpackIndex index , Path destination , InstanceInfo data , HashMap <String , HashData > hashes , Set <String > whitelistedDomains ) throws IOException {
30+ public MrPackInstaller (Path source , ModpackIndex index , Path destination , InstanceInfo data , HashMap <String , HashData > hashes , Set <String > whitelistedDomains , HashSet < String > nonOverwritablePaths ) throws IOException {
3031 this .source = source ;
3132 this .index = index ;
3233 this .currentInstanceData = data ;
@@ -38,6 +39,7 @@ public MrPackInstaller(Path source, ModpackIndex index, Path destination, Instan
3839 this .newHashes = new HashMap <>();
3940
4041 this .whitelistedDomains = whitelistedDomains ;
42+ this .nonOverwritablePaths = nonOverwritablePaths ;
4143 }
4244
4345 public void prepareFolders () throws IOException {
@@ -52,13 +54,14 @@ public void extractIncluded(Map<String, HashData> existingHashes) throws IOExcep
5254 Files .walkFileTree (path , new FileVisitor <Path >() {
5355 @ Override
5456 public FileVisitResult preVisitDirectory (Path dir , BasicFileAttributes attrs ) throws IOException {
55- var p = destination .resolve (path .relativize (dir ).toString ()).normalize ();
57+ var local = path .relativize (dir ).toString ();
58+ var p = destination .resolve (local ).normalize ();
5659 if (!p .startsWith (destination .toAbsolutePath ())) {
57- Logger .error ("Modpack contains files, that are placed outside of server's root! Found '%s'" , path . relativize ( dir ). toString () );
60+ Logger .error ("Modpack contains files, that are placed outside of server's root! Found '%s'" , local );
5861 return FileVisitResult .TERMINATE ;
5962 }
6063
61- if (Constants . NON_OVERWRITABLE . contains (p . toString () ) && Files .exists (p )) {
64+ if (nonOverwritablePaths . contains (local ) && Files .exists (p )) {
6265 Logger .warn ("Skipping non-overwritable path: %s" , path );
6366 return FileVisitResult .SKIP_SUBTREE ;
6467 }
@@ -75,7 +78,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
7578 return FileVisitResult .TERMINATE ;
7679 }
7780
78- if (Constants . NON_OVERWRITABLE . contains (outPath . toString () ) && Files .exists (file )) {
81+ if (nonOverwritablePaths . contains (local ) && Files .exists (file )) {
7982 Logger .warn ("Skipping non-overwritable file: %s" , path );
8083 return FileVisitResult .CONTINUE ;
8184 }
@@ -241,6 +244,8 @@ public void requestDownloads(FileDownloader downloader, Map<String, HashData> ha
241244
242245 for (var file : this .index .files ) {
243246 var currentHash = hashExisting .remove (file .path );
247+ var path = this .destination .resolve (file .path );
248+
244249 if (currentHash != null ) {
245250 var newHash = HashData .read (Constants .MODRINTH_HASH , file .hashes );
246251
@@ -250,6 +255,10 @@ public void requestDownloads(FileDownloader downloader, Map<String, HashData> ha
250255 } else if (currentHash .equals (newHash )) {
251256 this .newHashes .put (file .path , newHash );
252257 continue ;
258+ } else if (nonOverwritablePaths .contains (file .path ) && Files .exists (path )) {
259+ Logger .warn ("Skipping non-overwritable file: %s" , file .path );
260+ this .newHashes .put (file .path , this .oldHashes .get (file .path ));
261+ continue ;
253262 } else if (currentHash .equals (this .oldHashes .get (file .path ))) {
254263 Files .deleteIfExists (this .destination .resolve (file .path ));
255264 } else {
@@ -258,6 +267,9 @@ public void requestDownloads(FileDownloader downloader, Map<String, HashData> ha
258267 Logger .info ("File '%s' was modified, but modpack required it to be updated! Moving it to '%s'" , file .path , "old_modified_files/" + file .path );
259268 Files .deleteIfExists (this .destination .resolve (file .path ));
260269 }
270+ } else if (nonOverwritablePaths .contains (file .path ) && Files .exists (path )) {
271+ Logger .warn ("Skipping non-overwritable file: %s" , file .path );
272+ continue ;
261273 }
262274
263275 for (var url : file .downloads ) {
@@ -266,7 +278,6 @@ public void requestDownloads(FileDownloader downloader, Map<String, HashData> ha
266278 }
267279 }
268280
269- var path = this .destination .resolve (file .path );
270281 if (Files .exists (path )) {
271282 Files .createDirectories (this .destinationOldModified .resolve (file .path ).getParent ());
272283 Files .deleteIfExists (this .destinationOldModified .resolve (file .path ));
0 commit comments