New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QON not save note correctly in some condition #635

Closed
vanleo2001 opened this Issue Jul 18, 2017 · 33 comments

Comments

Projects
None yet
2 participants
@vanleo2001

vanleo2001 commented Jul 18, 2017

QON doesn't save note correctly when I restore with shortcut "ctrl-z" immediately after I delete some lines .

Below is what I do:
(1) Open QON with an example note
snap740

(2) delete the last line
snap741

(3) restore with shortcut "ctrl-z", then "ctrl-s" to save it ( you can see the note is saved in log window)or just close the QON directly ( QON can autosave the note)
snap743

(4) restart QON, you can see the restore content does not be saved.
snap744

@pbek

This comment has been minimized.

Owner

pbek commented Jul 18, 2017

Thank you for reporting, I will try to reproduce your issue.

@pbek

This comment has been minimized.

Owner

pbek commented Jul 18, 2017

I wasn't able to reproduce that, the note with the "undone" removed line was always saved for me.

@pbek

This comment has been minimized.

Owner

pbek commented Jul 18, 2017

Same under Windows, it works for me. How did you delete the last line?

@vanleo2001

This comment has been minimized.

vanleo2001 commented Jul 18, 2017

open a note

  1. Select the last line with mouse, hit del key to delete it.
  2. Use "ctrl-z" to restore it
  3. "ctrl-s" to save it.
  4. Restart QON.

I will send you video via email

@vanleo2001

This comment has been minimized.

vanleo2001 commented Jul 18, 2017

Please check you email : office@bekerle.com

@pbek

This comment has been minimized.

Owner

pbek commented Jul 18, 2017

Got it, thank you.
I did exactly what you did (and I also tried backspace) and it always worked for me... :/

@vanleo2001

This comment has been minimized.

vanleo2001 commented Jul 18, 2017

In addition, I use another pc with os win8.1 pro, All QON setting is default.

  1. If setting -> general -> "Notify about all external modifications of the current note" is checked, When I exit QON after I do "delete lines and restore", an alert will ask me for saving note. Then it will save note correctly.

  2. Either setting -> general -> "Ignore all external modifications of the current note" OR " Accept all external modifications of the current note" is checked, when I exit QON after I do "delete lines and restore", it can't save note correctly.

@pbek

This comment has been minimized.

Owner

pbek commented Jul 18, 2017

Do you have some sync-tools or other 3rd party apps that are accessing the notes who might interfere?

@vanleo2001

This comment has been minimized.

vanleo2001 commented Jul 18, 2017

I have turned off the sync-tool, although the notes are kept in sync folder

@pbek

This comment has been minimized.

Owner

pbek commented Jul 18, 2017

Hmmm, I still think some other app might interfere with the note. So far I haven't found a way to reproduce this under windows. :/

@vanleo2001

This comment has been minimized.

vanleo2001 commented Jul 18, 2017

But I test in another PC with win 8.1 pro, which has no sync tools, the problem is same. Sadly!

@pbek

This comment has been minimized.

Owner

pbek commented Jul 18, 2017

What happens if you don't restart QOwnNotes after saving the note, but open the note file in an other editor. Is the restored line present in the other editor or not?

@vanleo2001

This comment has been minimized.

vanleo2001 commented Jul 18, 2017

Same as I said above, sadly. I'll try to debug it

@pbek

This comment has been minimized.

Owner

pbek commented Jul 18, 2017

"Same" in what way?

@vanleo2001

This comment has been minimized.

vanleo2001 commented Jul 18, 2017

  1. prepare a markdown file with 3rd editor. The content is below:
Note 2017-07-18
---

aaaaaaaaa
bbbbbbbb
ccccccccc
  1. Close the 3rd editor. Open this md file with QON

  2. select last line ccccccccc with mouse, del it, then "ctrl-z" to restore it.

  3. "ctrl-s" to save it. That should be no change in this md file.

  4. Don't close QON, open this md file with 3rd editor. You can see the older last line ccccccccc is missed

@pbek

This comment has been minimized.

Owner

pbek commented Jul 18, 2017

Thank you for testing, I've no idea why I can't reproduce that behavior...

@pbek

This comment has been minimized.

Owner

pbek commented Jul 18, 2017

It's done by MainWindow::storeUpdatedNotesToDisk() in https://github.com/pbek/QOwnNotes/blob/develop/src/mainwindow.cpp#L2441.

@vanleo2001

This comment has been minimized.

vanleo2001 commented Jul 19, 2017

Problem reproduce:

Step 1. Preapre the markdown file with content below, then save it.

Note 2017-07-18
---
aaaa
bbbb

Step 2. Open the md note with QON

Step 3. Select the last line bbbb with mouse, then hit del key to delete it at once. Now the note text is

Note 2017-07-18
---
aaaa

Step 4. Don't save note, just ctrl-z to restore text. Now the note text is:

Note 2017-07-18
---
aaaa
bbbb

Step 5. ctrl-s to save note, open it with 3rd editor, but the md file is

Note 2017-07-18
---
aaaa

Find in Debugger ollydbg and QON source

When current note text is modified in STEP 3,

void MainWindow::on_noteTextEdit_textChanged() will trigger first( ).
...
(text != noteTextFromDisk) {
this->currentNote.storeNewText(text);

Trace step into:
bool Note::store()
QON uses a memory databse to store the modified note with modified sign "has_dirty_data" , so the text is changed and stored in this db in STEP 3, also "has_dirty_data" is set as 1 which means text modified.

When I restore the note with shortcut ctrl-z in STEP 4,

The current note text is same as the md file on harddisc, when code runs:
(text = noteTextFromDisk) https://github.com/pbek/QOwnNotes/blob/develop/src/mainwindow.cpp#L4361
then the restore text doesn't fill in memory database. The memory database keeps the note text modified sign "has_dirty_data" as 1 and text in STEP 3

When I save the note in STEP 5,

QON will query the note text modified sign "has_dirty_data" in memory database. Because "has_dirty_data"=1 , QON stores the text (the text of STEP 3, but not text of STEP 4) from memory database onto harddisk. So the bug happens.

@pbek

This comment has been minimized.

Owner

pbek commented Jul 19, 2017

Good debugging, thank you! But I still have no idea why it doesn't happen for me and so I'm not sure what I should do for your issue. :( Or do you see an obvious problem that can be fixed in the source code?

@vanleo2001

This comment has been minimized.

vanleo2001 commented Jul 20, 2017

I send you email attached videos about the action of QON in my host win7 and MAC OS in VMWare virtual machine. Both in these 2 OS platform , QON ver 17.07.4 can't save note correctly.

Every step I do in video is:

  1. clear all settting in QON.
  2. run QON in default setting, except set language as english.
  3. run QON, create a new note, type in some random text, exit.
  4. restart QON, delete last line, restore it, exit. They are all done by mouse right menu clicking.
  5. restart QON, you can see note is saved uncorrectly.
  6. repeat step 4 and 5 several times.

BTW, sometimes after I do STEP 4, an alert windows will jump out. It ask me if I accept the external modifition or not. Then QON maybe save note correctly. But in most time this alert will not show even if I set "Notify about all external modifications of the current note" checked.

@pbek

This comment has been minimized.

Owner

pbek commented Jul 20, 2017

Thank you for your videos, so you also did it on macOS... I tried the same and the last line was always stored. I really want to know what the difference between our systems is.

@vanleo2001

This comment has been minimized.

vanleo2001 commented Jul 20, 2017

What is your operation system? with onwcloud or nextcloud on it?

@pbek

This comment has been minimized.

Owner

pbek commented Jul 20, 2017

  • Windows 8.1, KDE Neon, Manjaro Linux, mac OS
  • ownCloud or Nextcloud client
@vanleo2001

This comment has been minimized.

vanleo2001 commented Jul 20, 2017

I don't deploy the ownCloud or Nextcloud client.
I test in windows 7, windows 8.1 on real pc, MAC os on VM. QON save notes uncorrectly.

@pbek

This comment has been minimized.

Owner

pbek commented Jul 20, 2017

I will do more testing.

@pbek

This comment has been minimized.

Owner

pbek commented Jul 20, 2017

Do you care to build QOwnNotes yourself to test a change I made?
http://www.qownnotes.org/installation#building

diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 9a022aa..66008f0 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -4358,7 +4358,10 @@ void MainWindow::on_noteTextEdit_textChanged() {
     QString text = Utils::Misc::transformLineFeeds(
             ui->noteTextEdit->toPlainText());
 
-    if (text != noteTextFromDisk) {
+    // store the note to the database if the note text differs from the one
+    // on the disk or the note was already modified but not stored to disk
+    if ((text != noteTextFromDisk || currentNote.getHasDirtyData())) {
+        qDebug() << __func__ << " - 'note stored'";
         this->currentNote.storeNewText(text);
         this->currentNote.refetch();
         this->currentNoteLastEdited = QDateTime::currentDateTime();
@vanleo2001

This comment has been minimized.

vanleo2001 commented Jul 20, 2017

Great! It works correctly in windows 7.

@pbek

This comment has been minimized.

Owner

pbek commented Jul 20, 2017

Really? That's awesome! Thanks a lot for all the research and testing!

17.07.5

  • fixed a problem with correctly storing the note text when special note text
    changes were made between the note save intervals

@pbek pbek added this to the 17.07.5 milestone Jul 20, 2017

@vanleo2001

This comment has been minimized.

vanleo2001 commented Jul 20, 2017

You flush the memory database. In a strict sense, the restored note is not the real original note. But it works correctly. Thanks a lot!

@pbek

This comment has been minimized.

Owner

pbek commented Jul 20, 2017

I compared the note on the disk with the current note text but past changes within the interval were not stored to disk yet so it could happen that the note on the disk wasn't updated with the latest modifications. Although you did a much better job at triggering that behaviour than me... :)

@vanleo2001

This comment has been minimized.

vanleo2001 commented Jul 20, 2017

I know. The dafault setting of "note save interval time " is 10 sec. If deleting and restoring action is less than this interval time, QON will save uncorrectly because it need compare the current note and note on disk before it saves.

@pbek

This comment has been minimized.

Owner

pbek commented Jul 20, 2017

Exactly.

@pbek

This comment has been minimized.

Owner

pbek commented Jul 20, 2017

There now is a new release, could you please test it and report if it works for you?

@pbek pbek closed this Jul 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment