RSync - Merging Files

Jakob Jenkov
Last update: 2014-05-23

Once the differences between the new and the old files are detected, the old file needs to be merged with the changes from the new file, to create a copy of the new version of the file.

As you know, the computer containing the old version of the file, receives an instruction stream on how to construct the new version of the file. The instruction stream contains references to blocks in the old file that has not changed in the new version, as well as the sequences of data that are new.

To merge the old file with the new data sequences, the computer holding the old file iterates the instruction stream. When a block reference is encountered in the instruction stream, the corresponding block of data is copied from the old file to the new file. When a sequence of data is encountered in the instruction stream, that data is copied directly to the new file. This process continues until the end of the instruction stream. The new version of the file is then complete.

Here is a simple pseudo code outline of the process:

while( stream.hasMoreData() ) {

    if( stream.isBlockReference() ) {
      copyOldBlock(newFileOutputStream, stream.getBlockReference());
    }
    else if( stream.isDataSequence() ) {
      copyDataSequence(newFileOutputStream, stream);
    }

    stream.moveToNext();
}

Jakob Jenkov

Featured Videos

Java Generics

Java ForkJoinPool

P2P Networks Introduction



















Close TOC
All Tutorial Trails
All Trails
Table of contents (TOC) for this tutorial trail
Trail TOC
Table of contents (TOC) for this tutorial
Page TOC
Previous tutorial in this tutorial trail
Previous
Next tutorial in this tutorial trail
Next