Spyder: Cannot restore files between different drives in Windows

Created on 23 Jan 2019  路  7Comments  路  Source: spyder-ide/spyder

Issue Report Checklist

  • [x] Searched the issues page for similar reports
  • [x] Read the relevant sections of the Spyder Troubleshooting Guide 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)
  • [ ] Tried basic troubleshooting (if a bug/error)

    • [x] Restarted Spyder

    • [x] Reset preferences with spyder --reset

    • [ ] Reinstalled the latest version of Anaconda

    • [ ] Tried the other applicable steps from the Troubleshooting Guide

  • [x] Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

I keep getting this error message when trying to restore files. Spyder is open in drive D and backup file is in drive C.

image

What steps reproduce the problem?

  1. Closed spyder by Crtl+C while in bootstap mode from CMD, or even close Spyder without saving the file after some changes
  2. I always then keep getting a dialog asking to restore the file
  3. When I try to restore the file and error is displayed. Clicking OK does nothing!

The error states that the system cannot move the file between different drives. Therefore, I just discard the auto-saved file, to let Spyder launches.

What is the expected output? What do you see instead?

Paste Traceback/Error Below (if applicable)


PASTE TRACEBACK HERE

Versions

  • Spyder version: Spyder beta4.0 under development (forked today).
  • Python version: 3.6
  • Qt version:
  • PyQt version:
  • Operating System name/version: windows 10

Dependencies

PASTE DEPENDENCIES HERE

pygments >=2.0 : 2.3.1 (OK)
qdarkstyle >=2.6.4: 2.6.5 (OK)
sphinx >=0.6.6 : 1.8.3 (OK)
pyls >=0.19.0 : 0.19.0 (OK)
nbconvert >=4.0 : 5.4.0 (OK)
pandas >=0.13.1 : 0.23.4 (OK)
numpy >=1.7 : 1.15.4 (OK)
sympy >=0.7.3 : 1.3 (OK)
cython >=0.21 : 0.29.3 (OK)
qtconsole >=4.2.0 : 4.4.3 (OK)
IPython >=4.0 : 7.2.0 (OK)
matplotlib >=2.0.0: 3.0.2 (OK)
pylint >=0.25 : 2.2.2 (OK)

This might give an idea to the solution.
https://bugs.python.org/issue29805

Editor Bug

All 7 comments

@jitseniesen, could you take a look at this one? Thanks!

@Khalilsqu Thanks for the report. I think the solution is to change line 224 of recover.py from

except AttributeError:

to

except (AttributeError, OSError):

However, I don't have access to a Windows machine at the moment to test this. Can you please check whether this helps? Thanks.

Indeed it works, with your suggestion and the file is restored correctly.

But this change is necessary too

if PY2:
    import shutil

to

import shutil

otherwise a NameError is raised on py3

Thanks for checking.

I think probably shutil.move(autosave['name'], orig_name)

might replace all of

            try:
                os.replace(autosave['name'], orig_name)
            except AttributeError:  # Python 2
                shutil.copy2(autosave['name'], orig_name)
                os.remove(autosave['name'])

but maybe I am wrong!

shutil.move exists in both py2 and py3. and if the source and destination are in different file-system(disk drives), it will use first shutil.copy2 and then remove the file from source folder.

I also have another question, it is necessary to show the recovery (restore) dialog when the user decides not to save modified files when closing Spyder?

As I understand the documentation, shutil.move(src, dest) fails on Windows if dest already exists. Unfortunately.

I also have another question, it is necessary to show the recovery (restore) dialog when the user decides not to save modified files when closing Spyder?

It shouldn't. I think @CAM-Gerlach also mentioned this on Gitter. I'll have a look later today.

Thanks, indeed you are right,

https://stackoverflow.com/a/16845955/6814154

Was this page helpful?
0 / 5 - 0 ratings