don't fall over if cwd doesn't exist

This commit is contained in:
Damien Elmes 2012-02-13 12:16:52 +09:00
parent b89dde97a8
commit abf6e3fa13

View file

@ -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)
try:
self._oldcwd = os.getcwd() 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,6 +47,7 @@ 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
if self._oldcwd:
os.chdir(self._oldcwd) os.chdir(self._oldcwd)
def dir(self): def dir(self):