0

I have two base file filea.txt and fileb.txt. Trying to create signature, then delta using signature and fileb.txt, then patch filea.txt with that delta. Resulting file's contents should be same as fileb.txt

First part creates signature file from filea.txt:

#include <stdlib.h>
#include <stdio.h>
#include "librsync.h"

int main(){
    FILE *fpa;
    fpa = fopen("filea.txt","r");

    FILE *fps;
    fps = fopen("sig.sig","w+");


    rs_result res = rs_sig_file(fpa, fps, 1,2,NULL);

    fclose(fpa);
    fclose(fps);

    printf("Result code: %d\n", res);

    return 0;
}

Then the second one is supposed to use that signature with fileb.txt file to create delta file

#include <stdlib.h>
#include <stdio.h>
#include "librsync.h"


int main(){
    FILE *fpb;
    fpb = fopen("fileb.txt", "r");

    FILE *fpd;
    fpd = fopen("delta.delt","w+");

    FILE *sigFile;
    sigFile = fopen("sig.sig","r");

    rs_signature_t *signature;

    rs_loadsig_file(sigFile, &signature, NULL);

    rs_result res = rs_delta_file(signature, fpb, fpd, NULL);

    printf("Result: %d", res);

    fclose(fpb); fclose(fpd); fclose(sigFile);

    return 0;
}

I'm compiling both of them like this gcc -o delta create_delta.c -Wall -g -lrsync

But the second part gives Segmentation fault error.

Maybe because of this, third executable produces empty file:

int main() {
    FILE *fpd;
    fpd = fopen("delta.delt", "r");

    FILE *fpa;
    fpa = fopen("filea.txt", "r");

    FILE *fpn;
    fpn = fopen("file_new.txt", "w+");

    rs_patch_file(fpa, fpd, fpn, NULL);

    fclose(fpd); fclose(fpa); fclose(fpn);

    return 0;
}

UPDATE Tried checking file pointers for null after fopen didn't catch any errors.

Dulguun Otgon
  • 1,925
  • 1
  • 19
  • 38
  • 1
    You have absolutely no error checking on any of your calls to the standard library or to the rsync library functions `rs_loadsig_file`, `rs_patch_file`, etc - how do you expect to catch any problems ? – Paul R Jul 30 '14 at 07:26
  • Tried checking file pointers for null after fopen didn't catch any errors. – Dulguun Otgon Jul 30 '14 at 07:40
  • What about the rsync library calls though, particularly `rs_loadsig_file` ? – Paul R Jul 30 '14 at 07:43
  • `printf` just after `rs_loadsig_file` doesn't work. So I think `rs_loadsig_file` is making that error – Dulguun Otgon Jul 30 '14 at 07:51
  • OK - run under gdb - hit `bt` when you crash, then see if the resulting backtrace gives any clues. – Paul R Jul 30 '14 at 07:56

1 Answers1

4

After looking at https://rproxy.samba.org/doxygen/librsync/rsync_h.html i figured you have to use

rs_build_hash_table(signature)

before calling

rs_delta_file(signature, fpb, fpd, NULL);

Works fine for me then.

Optokopper
  • 203
  • 1
  • 5