Avoid update notes unnecessarilly and report note conflict #358
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.