Bionus / imgbrd-grabber

Very customizable imageboard/booru downloader with powerful filenaming features.
https://www.bionus.org/imgbrd-grabber/
Apache License 2.0
2.48k stars 216 forks source link

Favorites and Monitors lost after shutdown #2199

Open Roshri opened 3 years ago

Roshri commented 3 years ago

Grabber was running when I had a blackout. Upon powering up the pc and restarting, the pop-up about resuming previous session appeared, clicked on yes. Not only did previous session dissappear, I also lost all my favorites and monitors (which were well over 700). Is there a way to recover them?

EDIT: blacklist, ignore list, and viewlater weren't affected by this. In fact, everything stored in .txt was spared this purge. Favorites and Monitors aren't stored this way and were lost. I don't know what this means but maybe this could help?

Running on W10 Grabber ver 7.3.2 main.log settings.zip

Bionus commented 3 years ago

Very strange, out of everything those are absolutely supposed to be restored, since they are saved to the disk on every change (especially to avoid this kind of issues):

Favorites: https://github.com/Bionus/imgbrd-grabber/blob/08809d811e1cba243c9bc6f1cabcbbe28bc9b089/src/lib/src/models/profile.cpp#L301-L312

Monitors: https://github.com/Bionus/imgbrd-grabber/blob/08809d811e1cba243c9bc6f1cabcbbe28bc9b089/src/lib/src/models/monitor-manager.cpp#L60-L69

Some things such as the blacklist are not, but will be soon (see issue #2107), which if even more confusing since you said your blacklist was spared.


As for restoring them, I doubt the files will still be there (or just empty), but you can check in the settings folder for favorites.json or monitors.json (see configuration files doc).

If they're missing or empty, I'd say you're out of luck for monitors. For favorites, you can try to check the "thumbs" directory, there should be one for each favorite, named with the corresponding tag (as long as your favorites had an associated image).

Roshri commented 3 years ago

Yeah, checked both favorites.json and monitors.json and they were empty. I'll add them again manually from thumbs directory, thanks!

Figured I'd be out of luck but wanted to report it nonetheless

EDIT: Well, I was adding them back manually and after adding 10% or so it crashed again and I lost all of the favorites again. But the monitors were kept.

sbobbo commented 3 years ago

I have lost mine before too. I religiously back up my file due to this. There seems to be some sort of unclean crash that saves that file and injects dirty data that can't be parsed, and on next launch Grabber nukes the file. Manually editing the file in the wrong way and then launching grabber is an easy way to see that behavior.

brazenvoid commented 3 years ago

I also lost my downloads, monitors and tabs recently due to a crash. For some reason favorites survived...

Bionus commented 3 years ago

Interesting, I'll check that out. In that case the issue is not that they're not saved properly, it's that they're destroyed during some crashes for some reason.

I'll investigate but I have some idea why would this happen. In any case adding at least a few more securities around the writing of those files seem required. The fact that it happens especially during crashes is strange though, since crashing shouldn't do anything, since it's well... crashing. 🤔

brazenvoid commented 3 years ago

You know, a couple weeks back I lost everything except MD5s in the DB, due to an unscheduled electric shutdown. So it really does not need a crash to make such happen.

brazenvoid commented 3 years ago

Oh, why not try archiving them in the db too?

Bionus commented 3 years ago

Strange because I hard exit the program quite often and I never had this happen. In that case it might also be because they're not closed properly 🤔

I guess I'll have to run some valgrind checks on Linux :|

sbobbo commented 3 years ago

I don't think I have ever encountered this with a clean exit/close of the program. IIRC, it's always been preceded by things like my computer crashing or blue screening, the program itself crashing, or windows deciding to reboot without my permission. Well, those examples, or when my manual editing of the file includes a screwup that breaks the schema in some way(like an extra space or bracket in the wrong spot), but that's obviously my own fault. The only reason I mention it is that the result is the same. On the next launch of Grabber, the corrupted file will be destroyed completely and a new 1KB favorites.json gets created.

yami-no-tusbas commented 3 years ago

Assuming favorite and monitors are set before leaving grabber, wouln't it be great to have grabber creating a ".bak" (backup copy) file fo thoses two ? Then once a user add manually an entry, or after some time (like 24h), update (re-create) thoses ".bak", so if something break, user still have a day old backup ? Then if there is a fail, user can simply go to Grabber settings folder, rename thoses ".bak" into what they are supposed to be and voilà.

In fact this is what i do manually each time I add some favs and monitors, just to be sure.

Bionus commented 3 years ago

Assuming favorite and monitors are set before leaving grabber

They're set on every change. And, from what I see of this issue, on crashes too for some reason.

wouln't it be great to have grabber creating a ".bak" (backup copy) file fo thoses two ? Then once a user add manually an entry, or after some time (like 24h), update (re-create) thoses ".bak", so if something break, user still have a day old backup ?

In theory yes, but if you can't trust Grabber to write the normal JSON files, can you trust it to write the BAK ones? 😅

yami-no-tusbas commented 3 years ago

In theory yes, but if you can't trust Grabber to write the normal JSON files, can you trust it to write the BAK ones? 😅

Because instead of re-creating the file from scratch, it would be a copy of the existing one, like on start, copy the file, exept if it is empty ? So if for any reason on closing the file get emptied, then, user still have a previous version, not empty. User have to close app, go to grabber folder, delete bugged file and rename backup.

Assuming grabber can do simple thing like copy/paste a file without editing it.

I was thinking something like this. Sorry it is php code, but it is what i know the best. exemple for one file :

//on launch
//check if monitors.json exist
if(file_exists(monitors.json)){
    //check existence of backup.
    if(file_exists(monitors.json.bak) && !empty(monitors.json.bak)){
        //we have to be sure it is not empty and exist.
        //then we check time.
        if(filemtime(monitors.json.bak) <= strtotime("-1 day"))
        {
            //file is too recent, don't touch it
            exit();
        }else{
            //file is old, update it.
            copy(monitors.json,monitors.json.bak);
            exit();
        }
    }else{
        //the monitors.json.bak don't exist or is empty
        //we copy the existing monitors.json to it
        copy(monitors.json,monitors.json.bak);
        exit();
    }
}else{
    //monitors.json does not exist.
    //check presence of backup to restore.
    if(file_exists(monitors.json.bak) && !empty(monitors.json.bak))
    {
        //then use the backup; no need to check date here.
        copy(monitors.json.bak,monitors.json);
        exit();
    }else
    {//nothing to do, if it does not exsist, app will create it on closing.
        exit();
    }
}

I know there is a simplier way to wrote this code (and shorter), but i want it to be clear. This should cover most case, but you have first to correct he bug that delete them.

brazenvoid commented 3 years ago

This issue refers to the bug that when grabber crashes it still writes to the original files which essentially corrupts them. The next time it launches, it regards them correctly as corrupted and deletes them. It can be made so that these are not deleted but copied to a .bak.

This perhaps can help in diagnosing the cause or actually what gets regarded as corrupt.

Still I think Jack is onto it and he will diagnose the real problem and these workarounds need not take his time.

sbobbo commented 3 years ago

I actually have a corrupted file! My computer bluescreened last night, and it must have been while my monitors were running. This morning I noticed and backed up the file before opening it up. Sure enough, the corrupted file had the same size as my normal file, but upon opening in Notepad++, all i see is "NULNULNUL", etc. Upon launching Grabber, it destroyed the file and replaced it with a 1KB blank favorites file. So this seems to match my prior experiences, except that this time i backed up the corrupted file.

@Bionus I'll send you the file.

yami-no-tusbas commented 3 years ago

Hey, i'm digging it up !

I got a current failure, my computer just stopped because of that, and surprise !!! Monitors is full of garbage, and favorite got emptied !

Here is the monitor file after hard reset, the file as a size, but show as full of "nul" character, maybe you can guess something out.

monitors.json.txt

Thankfully I made a backup some week ago !

ghost commented 3 years ago

Have the same problem... must have happened a few days ago... I was already wondering why Grabber wouldn't download things on startup. Luckily have a backup but its several month old so I still have to add hundreds manually...

ghost commented 3 years ago

Nevermind... even the favorites.json in the backup folder is empty... wtf

timidtax commented 2 years ago

Had the same issue, this is the third time now I have shut off my computer, only to find all my monitors and favorites deleted when I turned it back on.

Bionus commented 2 years ago

Re-opening because while I did push a fix, I was never able to ever reproduce the original issue, so I can't guarantee it actually fixes the problem. But it hopefully should. 😄

I'll close once people confirm it's indeed fixed.