@@ -335,7 +335,7 @@ private static void migrateConfigDirectory(Path configDirectory) {
335335 }
336336 for (Map .Entry <String , JsonObject > provider : providers .entrySet ()) {
337337 try {
338- writeAtomicIfChanged (configDirectory .resolve (provider .getKey () + "-orespawn.json" ), provider .getValue ());
338+ writeProviderIfAbsent (configDirectory .resolve (provider .getKey () + "-orespawn.json" ), provider .getValue ());
339339 } catch (IOException failure ) {
340340 REPORT .add ("provider_write_failed=" + provider .getKey () + ":" + failure .getClass ().getSimpleName ());
341341 LOGGER .error ("Could not write migrated OS3 provider {}" , provider .getKey (), failure );
@@ -792,6 +792,16 @@ private static int metadata(String block, String state) {
792792 return 0 ;
793793 }
794794
795+ static void writeProviderIfAbsent (Path destination , JsonObject value ) throws IOException {
796+ // An existing OS4 file is a pack's choice, even on its first legacy import.
797+ if (Files .isRegularFile (destination )) {
798+ REPORT .add ("provider_preserved=" + destination .getFileName ());
799+ return ;
800+ }
801+
802+ writeAtomicIfChanged (destination , value );
803+ }
804+
795805 private static void writeAtomicIfChanged (Path destination , JsonObject value ) throws IOException {
796806 byte [] data = (GSON .toJson (value ) + System .lineSeparator ()).getBytes (StandardCharsets .UTF_8 );
797807 if (Files .isRegularFile (destination ) && Arrays .equals (Files .readAllBytes (destination ), data )) {
@@ -833,7 +843,8 @@ private static void writeHumanUpgradeReport(Path destination) throws IOException
833843 String lower = row .toLowerCase (java .util .Locale .ROOT );
834844 if (lower .startsWith ("config_source=" ) || lower .startsWith ("resource_loaded=" )
835845 || lower .startsWith ("config_registered=" )) sources .add (row );
836- if ((lower .startsWith ("provider_written=" ) || lower .startsWith ("provider_unchanged=" ))
846+ if ((lower .startsWith ("provider_written=" ) || lower .startsWith ("provider_unchanged=" )
847+ || lower .startsWith ("provider_preserved=" ))
837848 && !lower .contains ("migration-report" )) providers .add (row );
838849 if (lower .contains ("_failed=" ) || lower .contains ("_rejected=" )
839850 || lower .contains ("_ignored=" ) || lower .contains ("_unresolved=" )
@@ -842,12 +853,12 @@ private static void writeHumanUpgradeReport(Path destination) throws IOException
842853 }
843854 }
844855 List <String > lines = new ArrayList <>();
845- lines .add ("OreSpawn 4.1.0 .112021 Upgrade Report" );
856+ lines .add ("OreSpawn 4.1.1 .112021 Upgrade Report" );
846857 lines .add ("================================" );
847858 lines .add ("" );
848859 lines .add ("RESULT: Legacy OreSpawn configuration was consumed and translated for OS4." );
849860 lines .add ("- Legacy sources read: " + sources .size ());
850- lines .add ("- OS4 provider files written or verified : " + providers .size ());
861+ lines .add ("- OS4 provider files written or retained : " + providers .size ());
851862 lines .add ("- Unique items requiring review: " + warnings .size ());
852863 lines .add ("" );
853864 lines .add (warnings .isEmpty ()
0 commit comments