update after merging from upstream

This commit is contained in:
vcoppe 2023-07-16 16:44:12 +02:00
parent 1c4fcc8969
commit c454b5a71d

View file

@ -13,78 +13,78 @@ import btools.util.ProgressListener;
final public class Rd5DiffApplier implements ProgressListener final public class Rd5DiffApplier implements ProgressListener
{ {
public static void main( String[] args ) throws Exception public static void main(String[] args) throws Exception
{ {
applyDiffs( new File( args[0] ),new File( args[1] ),new File( args[2] ) ); applyDiffs(new File(args[0]), new File(args[1]), new File(args[2]));
} }
/** /**
* Apply diffs for all RD5 files * Apply diffs for all RD5 files
*/ */
public static void applyDiffs( File segmentsDir, File diffDir, File outDir ) throws Exception public static void applyDiffs(File segmentsDir, File diffDir, File outDir) throws Exception
{ {
Rd5DiffApplier progress = new Rd5DiffApplier(); Rd5DiffApplier progress = new Rd5DiffApplier();
outDir.mkdir(); outDir.mkdir();
File[] fileSegments = segmentsDir.listFiles(); File[] fileSegments = segmentsDir.listFiles();
Arrays.sort( fileSegments, Comparator.comparing(File::getName) ); Arrays.sort(fileSegments, Comparator.comparing(File::getName));
for( File fs : fileSegments ) for (File fs : fileSegments)
{ {
String name = fs.getName(); String name = fs.getName();
if ( !name.endsWith( ".rd5" ) ) if (!name.endsWith(".rd5"))
{ {
continue; continue;
} }
File newSegment = new File( outDir, name ); File newSegment = new File(outDir, name);
newSegment.createNewFile(); newSegment.createNewFile();
Rd5DiffTool.copyFile( fs, newSegment, progress ); Rd5DiffTool.copyFile(fs, newSegment, progress);
newSegment.setLastModified( fs.lastModified() ); newSegment.setLastModified(fs.lastModified());
String basename = name.substring( 0, name.length() - 4 ); String basename = name.substring(0, name.length() - 4);
File segmentDiffDir = new File( diffDir, basename ); File segmentDiffDir = new File(diffDir, basename);
if ( segmentDiffDir.isDirectory() ) if (segmentDiffDir.isDirectory())
{ {
File[] segmentDiffFiles = segmentDiffDir.listFiles(); File[] segmentDiffFiles = segmentDiffDir.listFiles();
Arrays.sort( segmentDiffFiles, Comparator.comparingLong(File::lastModified) ); Arrays.sort(segmentDiffFiles, Comparator.comparingLong(File::lastModified));
for ( File segmentDiff : segmentDiffFiles ) for (File segmentDiff : segmentDiffFiles)
{ {
String diffName = segmentDiff.getName(); String diffName = segmentDiff.getName();
if ( !diffName.endsWith( ".df5" ) ) if (!diffName.endsWith(".df5"))
{ {
continue; continue;
} }
if ( segmentDiff.lastModified() <= fs.lastModified() ) if (segmentDiff.lastModified() <= fs.lastModified())
{ {
continue; // diff is older than segment continue; // diff is older than segment
} }
if ( segmentDiff.length() == 0L ) if (segmentDiff.length() == 0L)
{ {
continue; // avoid changing date for empty diff continue; // avoid changing date for empty diff
} }
System.out.println( "Applying diff " + segmentDiff.getName() + " to segment: " + name ); System.out.println("Applying diff " + segmentDiff.getName() + " to segment: " + name);
File tmpSegment = new File( outDir, "tmp.rd5" ); File tmpSegment = new File(outDir, "tmp.rd5");
tmpSegment.createNewFile(); tmpSegment.createNewFile();
Rd5DiffTool.recoverFromDelta( newSegment, segmentDiff, tmpSegment, progress ); Rd5DiffTool.recoverFromDelta(newSegment, segmentDiff, tmpSegment, progress);
newSegment.delete(); newSegment.delete();
tmpSegment.renameTo( new File( outDir, name ) ); tmpSegment.renameTo(new File(outDir, name));
newSegment = new File( outDir, name ); newSegment = new File(outDir, name);
newSegment.setLastModified( segmentDiff.lastModified() ); newSegment.setLastModified(segmentDiff.lastModified());
} }
} }
} }
} }
@Override @Override
public void updateProgress( String progress ) { } public void updateProgress(String task, int progress) { }
public boolean isCanceled() public boolean isCanceled()
{ {