Question

Currently I have the following part code in my Sync:

...

int index = file.find(remoteDir);
if(index >= 0){
    file.erase(index, remoteDir.size());
    file.insert(index, localDir);
}

...

// Uses PUT command on the file

Now I want to do the following instead:

  • If a file is the same as before, except for a rename, don't use the PUT command, but use the Rename command instead

TL;DR: Is there a way to check whether a file is the same as before except for a rename that occurred? So a way to compare both files (with different names) to see if they are the same?

Was it helpful?

Solution 2

I first tried to use Renjith method with md5, but I couldn't get it working (maybe it's because my C++ is for windows instead of Linux, I dunno.)

So instead I wrote my own function that does the following:

  • First check if the file is the exact same size (if this isn't the case we can just return false for the function instead of continuing).
  • If the sizes do match, continue checking the file-buffer per BUFFER_SIZE (in my case this is 1024). If the entire buffer of the file matches, return true.

PS: Make sure to close any open streams before returning.. My mistake here was that I had the code to close one stream after the return-statement (so it was never called), and therefore I had errno 13 when trying to rename the file.

OTHER TIPS

check the md5sum, if it is different then the file is modified. md5 check sum of a renamed file will remain same. Any change in content of file will give a different value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top