Merge pull request #919 from antlarr/fix-crash-in-getcwd

PICARD-1306: Fix crash opening the options dialog if cwd doesn't exist
This commit is contained in:
Laurent Monin
2018-08-08 14:47:54 +02:00
committed by GitHub
2 changed files with 14 additions and 2 deletions

View File

@@ -369,7 +369,13 @@ class File(QtCore.QObject, Item):
if sys.platform == "darwin":
new_filename = unicodedata.normalize("NFD", new_filename)
return os.path.realpath(os.path.join(new_dirname, new_filename))
new_path = os.path.join(new_dirname, new_filename)
try:
return os.path.realpath(new_path)
except FileNotFoundError:
# os.path.realpath can fail if cwd doesn't exist
return new_path
def _rename(self, old_filename, metadata):
new_filename, ext = os.path.splitext(

View File

@@ -23,6 +23,7 @@ import struct
import sys
import unicodedata
from picard.util import _io_encoding, decode_filename, encode_filename
from PyQt5.QtCore import QStandardPaths
def _get_utf16_length(text):
@@ -301,7 +302,12 @@ def make_short_filename(basedir, relpath, win_compat=False, relative_to=""):
"""
# only deal with absolute paths. it saves a lot of grief,
# and is the right thing to do, even for renames.
basedir = os.path.abspath(basedir)
try:
basedir = os.path.abspath(basedir)
except FileNotFoundError:
# os.path.abspath raises an exception if basedir is a relative path and
# cwd doesn't exist anymore
basedir = QStandardPaths.writableLocation(QStandardPaths.MusicLocation)
# also, make sure the relative path is clean
relpath = os.path.normpath(relpath)
if win_compat and relative_to: