[Bug] Npp loses all open files after restarting as Admin
-
@mkupper said in [Bug] Npp loses all open files after restarting as Admin:
A collision seems very unlikely. A new 1 file gets saved using a file name that looks like new 1@2024-02-02_164529 where 2024-02-02_164529 is the date/time the backup file is created. Notepad++ then refreshes the backup every seven seconds.
A collision is certain. Did you try firing up two instances and having a
new 1
(soft-named) file in each, and watch the backup directory as you change text in each instance? Only one backup file is created and maintained.Interestingly, however, if you create a hard-named file in the file system, and open that in each instance, and watch the backup directory, two files are created and maintained.
Experiments conducted with N++ 8.6.2.
-
@Alan-Kilborn said in [Bug] Npp loses all open files after restarting as Admin:
A collision is certain. Did you try firing up two instances and having a new 1 (soft-named) file in each, and watch the backup directory as you change text in each instance? Only one backup file is created and maintained.
I actually discovered this a while back, and Don Ho’s response (which I think makes sense) was that
NPPM_INTERNAL_SETFILENAME
(which AFAIK is the only way to get two files with the same “soft” name) is not something that plugins are supposed to use. -
@Mark-Olson said in [Bug] Npp loses all open files after restarting as Admin:
(which AFAIK is the only way to get two files with the same “soft” name)
My discussion in this thread is about two instances running. In this situation, one can easily have two soft-named files with the name
new 1
simultaneously – one in each instance.I’m not saying I care…much. I don’t use soft-named files (ever) and I don’t use multiple instances of the same Notepad++ (ever), but I thought it might be interesting to investigate at a user-level how the backup system in Notepad++ works in such a case, based upon @mkupper 's first comment in this thread.
-
Thanks everyone for the thought provoking comments here. I think I am now able to simulate the problem reported. And I have some answers to how the N++ backup feature works at these circumstances (had some fun with debugging of multiple instances of the same app in the same dir … )
There is no possible backup collision in between that two N++ multi-inst instances because that N++ backup feature will only work for the 1st instance and not for the other ones. Here is a backtrace why:
In short - the following winmain.cpp code (setting the cmdLineParams._isNoSession to true because it is not TheFirstOne) results also in not activating the backup function in any non-1st N++ instance at the end:
if (nppGUI._multiInstSetting == multiInst) { isMultiInst = true; // Only the first launch remembers the session if (!TheFirstOne) cmdLineParams._isNoSession = true; }
So to reproduce the OP’s issue:
- set the N++ multi-instance mode (either via the Preferences > Multi-Instance & Date > Muti-instance settings == Always… or via the “-multiInst” cmdline param) & restart N++
- open 1st instance of N++ (this one will have the N++ backup feature working)
- launch the 2nd one, create there some unsaved tabs with data, then try to open-edit-save a file in a restricted folder (e.g. in C:\Windows\) in it
- click Yes in the “Do you want to launch N++ in admin-mode?” msgbox
- 3rd N++ instance (now with admin-rights) will be opened but there will not be the unsaved/unbackuped file-tabs form the previous 2nd instance, see the pic
I am not saying that this is all an optimal behavior but a data loss reported here is possibly caused only by a user hands (probably closing of the 2nd unbackuped multi-inst N++) and not by a N++ code failure.
@PeterJones
I quickly checked the N++ user manual and there is not(?) an explicit note about such multi-inst setup influencing that backup feature in the way I described. If so, could you please add a short note both in the Preferences “Multi-Instance and Date” and in the “Backup” sections? I mean e.g. something like “Warning: The Notepad++ backup feature in multi-instance setups will work only for the 1st Notepad++ instance.” -
@xomx said in [Bug] Npp loses all open files after restarting as Admin:
if so, could you please add a short note
-
@xomx said :
There is no possible backup collision in between that two N++ multi-inst instances because that N++ backup feature will only work for the 1st instance and not for the other ones
This seems to go against what I was seeing in my earlier statements.
Perhaps my experiments were invalid because my setting was always “mono-instance” and I was opening two instances of the same Notepad++ with the-multiInst
command line parameter… -
@Alan-Kilborn
Right you are, it is even more complicated.
N++ Preferences setting and the cmdline-multiInst
is not equivalent, this is a mess!So what I wrote previously above only applies to the Preferences setting, with the cmdline setting the N++ backup function is also enabled on other N++ instances and they “happily” overwrite each other’s “new 1” documents backups (I tested). This definitely needs a fix!
-
Issue (& PR for testing):
https://github.com/notepad-plus-plus/notepad-plus-plus/issues/14691 -
This seems similar:
https://github.com/notepad-plus-plus/notepad-plus-plus/issues/14694
-