Skip to content

Commit

Permalink
Merge pull request #5340 from dalthviz/fixes_issue_5183
Browse files Browse the repository at this point in the history
PR: Add handling for OSError's when changing directories.
  • Loading branch information
ccordoba12 authored Sep 29, 2017
2 parents 538560e + e62893d commit 308455f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
16 changes: 9 additions & 7 deletions spyder/plugins/workingdirectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,13 @@ def chdir(self, directory, browsing_history=False,
self.histindex = len(self.history)-1

# Changing working directory
os.chdir(directory)
try:
os.chdir(directory)
if refresh_explorer:
self.set_explorer_cwd.emit(directory)
if refresh_console:
self.set_current_console_wd.emit(directory)
self.refresh_findinfiles.emit()
except OSError:
self.history.pop(self.histindex)
self.refresh_plugin()

if refresh_explorer:
self.set_explorer_cwd.emit(directory)
if refresh_console:
self.set_current_console_wd.emit(directory)
self.refresh_findinfiles.emit()
14 changes: 12 additions & 2 deletions spyder/widgets/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# Local imports
from spyder.config.base import _
from spyder.py3compat import (getcwd, str_lower, to_binary_string,
to_text_string, PY2)
to_text_string)
from spyder.utils import icon_manager as ima
from spyder.utils import encoding, misc, programs, vcs
from spyder.utils.qthelpers import (add_actions, create_action, file_uri,
Expand Down Expand Up @@ -1126,8 +1126,15 @@ def chdir(self, directory=None, browsing_history=False):
self.history.append(directory)
self.histindex = len(self.history)-1
directory = to_text_string(directory)
if PY2:
try:
PermissionError
FileNotFoundError
except NameError:
PermissionError = OSError
if os.name == 'nt':
FileNotFoundError = WindowsError
else:
FileNotFoundError = IOError
try:
os.chdir(directory)
self.parent_widget.open_dir.emit(directory)
Expand All @@ -1136,6 +1143,9 @@ def chdir(self, directory=None, browsing_history=False):
QMessageBox.critical(self.parent_widget, "Error",
_("You don't have the right permissions to "
"open this directory"))
except FileNotFoundError:
# Handle renaming directories on the fly. See issue #5183
self.history.pop(self.histindex)


class ExplorerWidget(QWidget):
Expand Down

0 comments on commit 308455f

Please sign in to comment.