Repository: spyder-ide/spyder

Issue:
Unable to save file to mapped network drive on Windows 7

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [X] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [x] Tried basic troubleshooting (if a bug/error)
    * [ ] Restarted Spyder
    * [ ] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

When I try to save a file to a network drive, I get the following error dialog:
``"Unable to save file 'my_file.py'
Error message:
[Errno 2] No such file or directory: '\\\\sshfs\\deu219564@10.50.229.93\\\\testscripts\\my_file.py'
``

This is new in Spyder 4.1.1, it worked in 4.1.0.

### What steps reproduce the problem?

1. Open a file (or create a new one) from a mapped network drive (e.g., X:)
2. Make some change to it
3. Try to save it

### What is the expected output? What do you see instead?

No error dialog poping out and the change in file when reopening it.

### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->
There  is no output in internal console.

However, I did some debugging on my own and the problem is in the file
[..]\site-packages\spyder\utils\encoding.py" line 245:
``
            absolute_filename = to_text_string(
                pathlib.Path(filename).resolve())
``
When I replace line with ``absolute_filename = osp.realpath(filename)`` it saves file correctly (without error).

## Versions

* Spyder version: Spyder 4.1.1 
* Python version: Python 3.6.3 64-bit
* Qt version: Qt 5.12.6
* PyQt version: PyQt5 5.12.3
* Operating System name/version: Windows 7

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
PASTE DEPENDENCIES HERE
```



Discussion:
@dalthviz, please take care of this one to see if we can include a fix for it in 4.1.2.

Resolving patch:
diff --git a/spyder/utils/encoding.py b/spyder/utils/encoding.py
--- a/spyder/utils/encoding.py
+++ b/spyder/utils/encoding.py
@@ -242,8 +242,11 @@ def write(text, filename, encoding='utf-8', mode='wb'):
 
     if os.name == 'nt':
         try:
-            absolute_filename = to_text_string(
-                pathlib.Path(filename).resolve())
+            absolute_path_filename = pathlib.Path(filename).resolve()
+            if absolute_path_filename.exists():
+                absolute_filename = to_text_string(absolute_path_filename)
+            else:
+                absolute_filename = osp.realpath(filename)
         except (OSError, RuntimeError):
             absolute_filename = osp.realpath(filename)
     else:


Test patch: