Hi.
I've been facing this issue for a couple of weeks now. My system is Manjaro Linux with Xfce 4.18 and I'm using Geany daily. (BTW I also have saved my Xfce user session to find back my windows where I want them to be).
I've noticed when I boot my system, sometimes, on random occasions, Geany's configuration has been overwritten with the defaults. It doesn't occur everytime I shut down my system, only randomly and _I haven't been able to find a pattern_. This is really annoying and the only way I've found so far is to restore my configuration from a backup.
I'm using a single F2FS filesystem on a NVMe drive, except for `/boot/efi`, which as required is located on a VFAT filesystem. I have no idea if this is important though. Geany is version 2.0, built 2023-10-23.
Cheers, π
Do you close Geany before shutting down or logging out?
Do you close Geany before shutting down or logging out?
No, I don't. Likewise I never close my windows when I shutdown my system.
Geany is not able to guarantee it will save its session before it is crashed by logout or shutdown.
There is a race between when Geany is signalled to close and when the logout/shutdown crashes Geany. That race is what means it works sometimes, but not every time, it totally depends on Geany access to the CPU, the disk IO etc in the time it has available, and remember those resources are shared with lots of other processes that you don't close, so there is no guarantee that Geany will get the resources it needs to complete saving the session.
Also it will be worse if a modified buffer is open since Geany will ask before saving it, but the user won't have a chance of responding so it just waits. Needs #3733 to remove that issue, then it may be possible to save session ahead of time so nothing needs to be saved at shutdown.
If it does not complete saving the session file may be left broken, so it gets rewritten to defaults some times.
There is no cross platform session management library at the moment despite GTK having an API for it, Gnome uses dbus, dunno what XFCE, KDE and other distros use, X11 has a session management library, and Windows and Macos are different again. At the moment applications are left with the sad choice of either specialising in a particular platform, or being cross platform and not being integrated with any session management, or using a lot of effort to support many platforms.
Geany is cross platform and does not have the effort to support each platform itself, so no session management happens and so the problem.
I think I understand what you describe. However Geany, to my recollection is the _only_ application that yields that erratic behaviour — as far as I remember of my 20 years using Linux, of course.
How about saving the configuration when it _actually changes_ instead of on exit? From what I know a lot of Linux applications do this, be it on a timer to avoid frantically committing to the disk if the user does change a lot of parameters in a short time.
I'm sure the design is as it is because there are reasons (which I'm not aware of) but that design choice itself causes this issue to happen in this case, right?
Geany is nearly 20 years old and works on the presumption from those times that applications will be properly closed before logging out or shutting down. This has not been changed since then.
It is good that the presumption is removed by more modern IDEs like Vscode, as well as other apps like browsers (and as all those use the same code base, they all inherit it) but until "somebody(s)" make the relevant changes to Geany the workaround is simply to close it before logging out/shutting down.
BTW I don't know if that may help you but from what I understand of GUI session management, it only involves window positioning, not their configuration — I'm not talking about GUI widgets, of course, which configuration *is* about positioning and look. For instance, `gedit` doesn't "remember" the documents that were opened, only its placement was stored in the GUI session.
This also happens to be the case for the applications I use. Not that I hereby assume that's how it should be done, of course, it's only what I've noticed so far. Then there's firefox, which saves changes as soon as they appear, most probably the way I described earlier.
Anyway, I know no application so far, except Geany, which saves its configuration upon exit.
Geany is nearly 20 years old and works on the presumption from those times that applications will be properly closed before logging out or shutting down. This has not been changed since then.
[...]
Makes sense indeed.
For instance, gedit doesn't "remember" the documents that were opened,
Horrors!!!! That would be totally unacceptable for Geany, so of course a "session" is more complex than just window size and position and includes all those files that are open, individual settings for each file (filetype, cursor position, etc). And then projects act like sessions too, adding to the complexity of what needs to be saved when.
@3-14152898 Do you have `files.use_atomic_file_saving` enabled under Preferences->Various? If I'm not mistaken, it's not enabled by default and with the normal `fwrite()` method that Geany uses otherwise it might happen that when you shutdown your system, the written data won't get flushed to the disk.
I was able to reproduce similar problem locally when my LSP plugin was crashing on unload during Geany termination which caused that session files weren't saved in this case and the whole session was lost.
I think Geany should _really_ use `g_file_set_contents()` for saving all the config files to avoid problems like this.
The default setting is `use_gio_unsafe_file_saving` which does the same as `use_atomic_file_saving` __and__ fixes the protections __and__ handles MS file systems that can't rename in some circumstances, such as files on cheap file servers. So its best to leave it as is.
But as @techee says those settings don't affect writing config files, session files and project files, so it would be a good idea to change it to something safer, either `g_file_replace()` since `g_file_set_contents()` but that might have issues on Windows. In fact that may be why Geany does not use `g_key_file_save_file` since it uses `g_file_set_contents`.
Oh wait, silly me, do it the Geany way, add an option for the file saving method for config files :stuck_out_tongue_winking_eye:
But as I said above, best to store everything along the way including modified buffers and settings and store nothing at shutdown.
The default setting is use_gio_unsafe_file_saving which does the same as use_atomic_file_saving
Sadly, this is only true for saving documents which use
https://github.com/geany/geany/blob/eea0a25d5de5914f6dfef99776c7a73e29dc6b5f...
and not for anything else like config files which use
https://github.com/geany/geany/blob/eea0a25d5de5914f6dfef99776c7a73e29dc6b5f...
So for config files it's either `fwrite()` or `g_file_set_contents()` and not the GIO variant - and `fwrite()` is the default variant in this case because `use_safe_file_saving` is disabled by default and the GIO option is ignored.
and fixes the protections and handles MS file systems that can't rename in some circumstances, such as files on cheap file servers. So its best to leave it as is.
If this is the case, I think it would be best to add the GIO variant to `utils_write_file()` - or precisely, unify `utils_write_file()` and `write_data_to_disk()` so there's just one implementation of file saving.
Sadly, this is only true for saving documents which use
Thats what I said you said, no need to repeat it again, we agree!!! Ok, maybe not used to it :grin:
so there's just one implementation of file saving.
If only users will put both local config and remote website files in the same place, but they don't and so no guarantee having them both using the same save method will work. I would use `g_replace_contents` for configs all the time, that is unlikely to be stored on the webserver ... probably.
@3-14152898 Do you have `files.use_atomic_file_saving` enabled under Preferences->Various?
Nope, it's unticked. `use_gio_unsafe_file_saving` is though. I'm a bit confused as to what to do... Shall I untick the latter? I guess not since it's designed to sort out those kinds of issues, if I got it right?
It would be best if you could verify that that enabling `files.use_atomic_file_saving` fixes your problem - then we'd be sure the problem is the file saving method and not something else. That would however require something like this: 1. Disable `files.use_atomic_file_saving` and keep restarting your computer with Geany open until Geany loses the configuration. 2. Enable `files.use_atomic_file_saving` and do at least 2x the number of restarts than in (1) at which point we might assume the problem is fixed by this settings.
I'm sorry for you in advance ;-)
The settings `use_gio_unsafe_file_saving` doesn't matter for configuration files, it's currently only used for open documents.
The settings use_gio_unsafe_file_saving doesn't matter for configuration files, it's currently only used for open documents.
And to be clear fixing that is what #3947 is about.
It would be best if you could verify that that enabling `files.use_atomic_file_saving` fixes your problem - then we'd be sure the problem is the file saving method and not something else. That would however require something like this:
1. Disable `files.use_atomic_file_saving` and keep restarting your computer with Geany open until Geany loses the configuration. 2. Enable `files.use_atomic_file_saving` and do at least 2x the number of restarts than in (1) at which point we might assume the problem is fixed by this settings.
I'm not sure I'm following you there. Like I said in https://github.com/geany/geany/issues/3946#issuecomment-2345794726 the option is already unchecked. I don't really understand what you want me to do exactly...
I'm not sure I'm following you there. Like I said in https://github.com/geany/geany/issues/3946#issuecomment-2345794726 the option is already unchecked. I don't really understand what you want me to do exactly...
In (1) above to verify you are still able to reproduce the issue (by having `files.use_atomic_file_saving` unchecked).
In (2) to verify that checking `files.use_atomic_file_saving` fixes the problem.
In (1) above to verify you are still able to reproduce the issue (by having `files.use_atomic_file_saving` unchecked).
Well, consider step 1 is already done then since it's been that way for quite a while now. I never changed that option. This is the context of the issue I reported here above.
In (2) to verify that checking `files.use_atomic_file_saving` fixes the problem.
Done. I'll report here as soon as I notice something :+1:
The idea with (1) was to get some baseline regarding how often it happens. Is it every restart, every 5 restarts, every 10 restarts?
Then, when you know that it e.g. happened every 3 restarts in (1) and you restarted the computer 10 times with (2) without any problem, we can be pretty sure this is the right fix.
The idea with (1) was to get some baseline regarding how often it happens. Is it every restart, every 5 restarts, every 10 restarts?
That analysis has already been performed, the title of this issue says it all: randomly (aka I could find no pattern).
In (2) to verify that checking `files.use_atomic_file_saving` fixes the problem.
It's been a few days since I switched these options : ![image](https://github.com/user-attachments/assets/526a10fd-0503-4c7b-adce-fb0fbf063...)
No config loss to report so far... Knocking on wood...
Closed #3946 as completed.
I confirm the issue I mentioned has never surfaced again since you suggested to check `use_atomic_file_saving`, not a single time. Therefore I think it is now reasonable to close this bug report, I hope you agree. Thanks a lot for your help :+1:
Yes, this should be fixed now thanks to https://github.com/geany/geany/pull/3950 which replaces the code used for saving config files with a more reliable method. This is now always used independently of whether `use_atomic_file_saving` config option is set or not.
Hi.
I'm not reopening this issue as I assume I'd have to submit a new bug but I believe this change has had a repercussion on how Geany saves files that appear to be symbolic links on Linux. Instead of copying the file, I created a symbolic link, edited and saved it. The latter operation made the file a regular file instead of saving the target of the symbolic link.
Same thing happens if the file is a hard link.
Is this a consequence of `use_atomic_file_saving` ?
Is this a consequence of use_atomic_file_saving ?
Yes. If you want symlinks preserved, you need to use `use_gio_unsafe_file_saving` and have `use_atomic_file_saving` disabled. This is why this is the default settings.
If you compiled Geany by yourself, the fix from https://github.com/geany/geany/pull/3950 resolves the issue you had with config files and then you can set the save method to whatever you wish.
If you compiled Geany by yourself, the fix from #3950 resolves the issue you had with config files and then you can set the save method to whatever you wish.
Just to be sure I get it, will symbolic and hard links also be preserved with that #3950 fix?
Regardless, I can wait until Geany is available with fresh fixes in Arch repos, it's not that urgent.
Just to be sure I get it, will symbolic and hard links also be preserved with that https://github.com/geany/geany/pull/3950 fix?
Yes. After #3950, saving config files became independent of the method used for saving documents.
github-comments@lists.geany.org