notepad-plus-plus / notepad-plus-plus

Notepad++ official repository
https://notepad-plus-plus.org/
Other
22.59k stars 4.57k forks source link

Sessions Are Overwritten When Files Are Innacessible #4061

Open TrevorKarjanis opened 6 years ago

TrevorKarjanis commented 6 years ago

Description of the Issue

Session files are destroyed when loading network mapped files that are not yet accessible. It seems the inaccessible files are removed from the session file. I frequently lose saved sessions, because most of my files are accessed over a network.

Steps to Reproduce the Issue

  1. Save a session that contains files from a mapped network drive.
  2. Disconnect the remote computer or the mapped network drive.
  3. Load the saved session.

Expected Behavior

The session file is not modified. For each file, the user is prompted to keep the file in the editor, because it does not exist anymore. This is the same behavior experienced when deleting an open file. The user can save the session again to overwrite it.

Actual Behavior

The inaccessible files are immediately removed from the session without a prompt.

Debug Information

Notepad++ v7.5.4 (64-bit) Build time : Jan 1 2018 - 01:50:29 Path : C:\Program Files\Notepad++\notepad++.exe Admin mode : OFF Local Conf mode : OFF OS : Windows 10 (64-bit) Plugins : DSpellCheck.dll JSMinNPP.dll mimeTools.dll NppConverter.dll PluginManager.dll

ArkadiuszMichalski commented 4 years ago

Simillar/same to https://github.com/notepad-plus-plus/notepad-plus-plus/issues/7931

@TrevorKarjanis In the meantime you can use plugin https://github.com/funap/npp-explorer-plugin, where this problem was fixed https://github.com/funap/npp-explorer-plugin/issues/20.

prodancer2015 commented 3 years ago

I support the initial issue of "Sessions Are Overwritten When Files Are Inaccessible". This has occurred with me recently, several times.

Condition I have 2 hard drives, both with Windows OS installed on each. I use one for gaming, but can use either OS/drives to do work using Notepad++.

If I create (Save Session) on Drive A, shut down and reload into Drive B, then open the saved session, Notepad++ erases the content of the session file replacing it with generic XML tags and values. This means the sessions stored in the file are now gone.

Cause I repeated the above conditions starting on Drive A, but this time created copy of the session file, accessed it with NotePad++ and changed the drive letter from C:\ to E:\ within the XML tags, resaved the copy naming it accordingly so I would know which is which.

When I rebooted into Drive B, and accessed the copy, all worked fine because I changed the Drive letter in the XML tags.

When the session file was created, the drive I was on was named C:\ drive, the standard naming in Windows OS. When I restarted into to Drive B OS, Drive A (C:) now becomes drive E:\ .

What happens is when NotePad++ tries to read the session file from another drive and if the file location does not exist, NotePad++ will erase the entire session file replacing it with generic XML tags and values.

Problem The problem is the erasing of the session file content, where Notepad should just not open it and give a warning that it cannot use the file, instead of erasing the contents like it does. NotePad++ should leave the contents of the session file alone unless I resave it with a new session.

sasumner commented 3 years ago

@prodancer2015

It seems you are relying on the session file that Notepad++ automatically saves/restores. Why not turn that off and use File menu's Save session and Load session commands to save a session file for each of your "drive" situations?

prodancer2015 commented 3 years ago

You failed to read my post properly The words "I create..." means I manually saved it using "File > Save Session". I did not use the automated saved session.

ArkadiuszMichalski commented 3 years ago

@prodancer2015 This is known bug https://github.com/notepad-plus-plus/notepad-plus-plus/issues/7931 or https://github.com/notepad-plus-plus/notepad-plus-plus/issues/8436, for not existing files in session (as when drives change letter, or with a long lack of access to it) Notepad++ should prompt for delete or keep this entry in session file (at least as an option in pref, or even always keept this entry). You can try use Explorer Plugin by funap that added this prompt (and is generally better for session management), but I don't know if it help in remote access.

sasumner commented 3 years ago

You failed to read my post properly The words "I create..." means I manually saved it using "File > Save Session". I did not use the automated saved session.

Sorry. There are a lot of non-English speakers posting issues here, and it is sometimes difficult to read implied meanings. Best to be totally explicit. With the clarification, it reads well now.

NeilS-Wpg commented 3 years ago

I'm posting here to add to the chorus of those requesting this issue receive attention. My experience:

After a recent Windows 10 update, key folder paths changed. Folders that were of form

C:\Users\neils\Documents\etc

now appear (in Windows Explorer, etc.) as

C:\Users\neils\OneDrive\Documents\etc

Notice new 3rd name in path. I won't discuss the Win10 & OneDrive specific issue any further here.

The first problem I encountered after the update was when I launched Notepad++, and only a (small) subset of the files specified in session.xml loaded, as the others had paths that had become invalid. Upon launch, npp did not issue any error or warning; it loaded what it could. Thinking there was an issue specific to npp (or maybe to SessMgr plug-in), I chased wild geese for a while before I realized that globally the path to Documents had changed.

What npp might do when it encounters a failed file load while restoring a session is the same as what a failed group copy in Windows Explorer does: issue a msgbox displaying the bad file path, and let the user choose among Retry, Skip This or Skip All (ie this and all subsequent load errors within this session restore job).

By remaining silent, it is likely a user will close npp, causing the session file to be freshly written with lost entries, the outcome described under different scenarios by others in this thread. (As best I recall, this did happen to me but I could recover thanks to the session file backup maintained by Session Manager plug-in.)

So inaccessible files that are skipped should probably not have their entries removed from the session file upon npp exit, and perhaps as well, a user initiated "Save session..".

An even more complete solution would save a copy of the original session file with a special name (maybe with date-time embedded, or maybe with a long random string), and, to instruct the user on the two step renaming that could bring the original session file back into use (after making whatever change is needed to make the file paths valid once more), and, to instruct the user on how to hand-edit the session file (in old Notepad) to fix bad paths.

There may be better ideas.

For completeness:

Notepad++ v7.8.6 (64-bit) Build time : Apr 21 2020 - 15:23:03 Path : C:\Program Files\Notepad++\notepad++.exe Admin mode : OFF Local Conf mode : OFF OS Name : Windows 10 Pro (64-bit) OS Version : 2004 OS Build : 19041.685 Plugins : BookmarksDook.dll ComparePlugin.dll ExtSettings.dll mimeTools.dll NavigateTo.dll NppConverter.dll NppExec.dll NppExport.dll NppSnippets.dll RunMe.dll SelectQuotedText.dll SessionMgr.dll SurroundSelection.dll VisualStudioLineCopy.dll XBrackets.dll zoomdisabler_x64.dll _CustomizeToolbar.dll

sasumner commented 3 years ago

After a recent Windows 10 update, key folder paths changed.

A recent Windows 10 update did that with OneDrive ? Ugh. Clearly, M$ has a much higher opinion of OneDrive than users (well, me especially) have. The kind of problem you describe is probably only the first one of several you'll see with OneDrive and Notepad++...

e-d-n-a commented 3 years ago

Well, I just noticed the same issue and believe this is a very common scenario.

I had a bunch of "older" files still open, of which several path had changed due to moving their folders to a (slightly) different location. I knew about it, as Notepad++ tells you which files' paths changed when trying to "Close All" (after saving a session manually). Though, I wouldn't have thought, that Npp just didn't save any information about these tabs/files in the saved session. I would have made all kind of backups and notes, if I expected this might happen. Now, I lost many tabs and cannot recover!

As a user I would expect, that a manually saved session ideally behaves exactly like the automatically saved session and saves everything as is (asking only about unsaved changes). I don't know, if something prevents the contents of moved files (tabs with incorrect paths) from getting restored again?

Yet, it wouldn't be a big problem, if at least all tabs and file paths were conserved in the manually saved session file. I planned on renaming the paths in the session file to get everything loaded correctly again anyways. That Npp silently discards all tabs with incorrect paths while saving a session really caught me by surprise.

Now I feel very anxious again about manually saving sessions (which I already do not use much). You actually have to manually backup the "actual" automatically generated Session.xml from AppData everytime to be save! And then you also need to compare these files to notice, if anything went missing!?!

Also, how should I correct the wrong paths of many opened tabs then? I guess, I have to backup, modify and restore the auto session file to achieve that. I didn't know, these sessions are so different, which only makes manual sessions even less useful and actually annoying!