mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
don't fall over if cwd doesn't exist
This commit is contained in:
parent
b89dde97a8
commit
abf6e3fa13
1 changed files with 7 additions and 2 deletions
|
@ -23,7 +23,11 @@ class MediaManager(object):
|
||||||
self._dir = re.sub("(?i)\.(anki2)$", ".media", self.col.path)
|
self._dir = re.sub("(?i)\.(anki2)$", ".media", self.col.path)
|
||||||
if not os.path.exists(self._dir):
|
if not os.path.exists(self._dir):
|
||||||
os.makedirs(self._dir)
|
os.makedirs(self._dir)
|
||||||
self._oldcwd = os.getcwd()
|
try:
|
||||||
|
self._oldcwd = os.getcwd()
|
||||||
|
except OSError:
|
||||||
|
# cwd doesn't exist
|
||||||
|
self._oldcwd = None
|
||||||
os.chdir(self._dir)
|
os.chdir(self._dir)
|
||||||
# change database
|
# change database
|
||||||
self.connect()
|
self.connect()
|
||||||
|
@ -43,7 +47,8 @@ class MediaManager(object):
|
||||||
self.db.close()
|
self.db.close()
|
||||||
self.db = None
|
self.db = None
|
||||||
# change cwd back to old location
|
# change cwd back to old location
|
||||||
os.chdir(self._oldcwd)
|
if self._oldcwd:
|
||||||
|
os.chdir(self._oldcwd)
|
||||||
|
|
||||||
def dir(self):
|
def dir(self):
|
||||||
return self._dir
|
return self._dir
|
||||||
|
|
Loading…
Reference in a new issue