geeknote
geeknote copied to clipboard
Avoid update notes unnecessarilly and report note conflict
Currently, gnsync uses mtime of the local and server notes to decide whether to update server or local notes. The problem is that by comparing the mtimes, gnsync can only know which note is newer than the other but not know whether they have been changed since the last sync, neither know whether they have conflicts or not. So it would update notes even they have not been changed since last sync, and if both the server and local copy of a note have been changed, it always overwrite the server note, causing the changes made on the side side lost.
This patch saves the mtimes for both server and local notes to a file and it will be used as a guideline for future sync. By comparing current mtimes of a note with the saved mtimes, gnsync could know exactly whether the note on server was changed or the note was changed locally or the note on both side were changed. Thus, it can always make right decision to sync notes.
If both local and server notes have been changed since last sync, gnsync will report the potential conflicts and suggest user to do merge. Upon conflicts, gnsync will download the server note and save it locally as a file prefixed with a dot and postfixed with a .rej extension. User could check the difference and do merge manually. After merged, user could sync the conflicting notebook again with a newly introduced option --merged to get the notebook in sync.