Community
    • Login

    [Bug] Npp loses all open files after restarting as Admin

    Scheduled Pinned Locked Moved General Discussion
    bugcrashadmin rights
    20 Posts 8 Posters 1.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Alan KilbornA
      Alan Kilborn @mkupper
      last edited by

      @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.

      Mark OlsonM 1 Reply Last reply Reply Quote 1
      • Mark OlsonM
        Mark Olson @Alan Kilborn
        last edited by

        @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.

        Alan KilbornA 1 Reply Last reply Reply Quote 0
        • Alan KilbornA
          Alan Kilborn @Mark Olson
          last edited by

          @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.

          1 Reply Last reply Reply Quote 1
          • xomxX
            xomx
            last edited by

            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:

            https://github.com/notepad-plus-plus/notepad-plus-plus/blob/5e6df259423680f82e98e42af31c996690a06e26/PowerEditor/src/Notepad_plus_Window.cpp#L403-L409

            https://github.com/notepad-plus-plus/notepad-plus-plus/blob/5e6df259423680f82e98e42af31c996690a06e26/PowerEditor/src/Parameters.h#L916

            https://github.com/notepad-plus-plus/notepad-plus-plus/blob/5e6df259423680f82e98e42af31c996690a06e26/PowerEditor/src/Notepad_plus_Window.cpp#L93

            https://github.com/notepad-plus-plus/notepad-plus-plus/blob/5e6df259423680f82e98e42af31c996690a06e26/PowerEditor/src/winmain.cpp#L529-L535

            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

            npp-mutliinst-admin-test.png

            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.”

            PeterJonesP Alan KilbornA 2 Replies Last reply Reply Quote 1
            • PeterJonesP
              PeterJones @xomx
              last edited by

              @xomx said in [Bug] Npp loses all open files after restarting as Admin:

              if so, could you please add a short note

              Added ⇒ backup section and Multi-Instance section

              1 Reply Last reply Reply Quote 2
              • Alan KilbornA
                Alan Kilborn @xomx
                last edited by

                @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…

                xomxX 1 Reply Last reply Reply Quote 1
                • xomxX
                  xomx @Alan Kilborn
                  last edited by xomx

                  @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!

                  xomxX 1 Reply Last reply Reply Quote 1
                  • xomxX
                    xomx @xomx
                    last edited by

                    Issue (& PR for testing):
                    https://github.com/notepad-plus-plus/notepad-plus-plus/issues/14691

                    Alan KilbornA 1 Reply Last reply Reply Quote 1
                    • Alan KilbornA
                      Alan Kilborn @xomx
                      last edited by

                      This seems similar:

                      https://github.com/notepad-plus-plus/notepad-plus-plus/issues/14694

                      1 Reply Last reply Reply Quote 0
                      • donhoD
                        donho
                        last edited by

                        Fixed in https://github.com/notepad-plus-plus/notepad-plus-plus/commit/76cfc5945ecf1bebabb52a032572ec7f6b7b6029

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors