1.16.3-rc1, assets copying: check if files are identically, else force extract (rename to .old)

This commit is contained in:
Bixilon 2020-09-07 21:00:32 +02:00
parent 652e0c3058
commit 06abdb64a8
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 24 additions and 2 deletions

View File

@ -145,6 +145,9 @@ public class Log {
}
public static void setLevel(LogLevels level) {
if (Log.level == level) {
return;
}
Log.info(String.format("Log level changed from %s to %s", Log.level, level));
Log.level = level;
}

View File

@ -13,11 +13,14 @@
package de.bixilon.minosoft.util;
import de.bixilon.minosoft.logging.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
public final class FolderUtil {
@ -31,7 +34,13 @@ public final class FolderUtil {
}
File out = new File(to + File.separator + entry);
if (out.exists()) {
continue;
// check
if (Files.mismatch(Path.of(entryFile.getPath()), Path.of(out.getPath())) == -1) {
// identically
continue;
}
// move file to an other location and re extract
moveFileToOld(out);
}
File outFolder = new File(out.getParent());
if (!outFolder.exists()) {
@ -40,4 +49,14 @@ public final class FolderUtil {
Files.copy(new FileInputStream(entryFile), out.toPath());
}
}
private static void moveFileToOld(File file) {
File newFile = new File(file.getAbsolutePath() + ".old");
if (newFile.exists()) {
newFile.delete();
Log.verbose(String.format("Deleted file: %s", newFile.getAbsoluteFile()));
}
file.renameTo(newFile);
Log.verbose(String.format("Renamed %s to: %s", newFile.getAbsoluteFile(), newFile.getName()));
}
}

File diff suppressed because one or more lines are too long