Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Add handling for OSError's when changing directories. #5340

Merged
merged 2 commits into from
Sep 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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