fix media dir problem on win32, fix unicode issues with media

This commit is contained in:
Damien Elmes 2009-01-05 08:20:49 +09:00
parent 2aecbffafe
commit 7e74fe3844
2 changed files with 5 additions and 4 deletions

View file

@ -1366,6 +1366,9 @@ where id = :id""", pending)
if self.path: if self.path:
# file-backed # file-backed
dir = re.sub("(?i)\.(anki)$", ".media", self.path) dir = re.sub("(?i)\.(anki)$", ".media", self.path)
if create == None:
# don't create, but return dir
return dir
if not os.path.exists(dir) and create: if not os.path.exists(dir) and create:
try: try:
os.mkdir(dir) os.mkdir(dir)
@ -1391,10 +1394,9 @@ Return new path, relative to media dir."""
def renameMediaDir(self, oldPath): def renameMediaDir(self, oldPath):
"Copy oldPath to our current media dir. " "Copy oldPath to our current media dir. "
assert os.path.exists(oldPath) assert os.path.exists(oldPath)
newPath = self.mediaDir(create=True) newPath = self.mediaDir(create=None)
# copytree doesn't want the dir to exist # copytree doesn't want the dir to exist
try: try:
os.rmdir(newPath)
shutil.copytree(oldPath, newPath) shutil.copytree(oldPath, newPath)
except: except:
# FIXME: should really remove everything in old dir instead of # FIXME: should really remove everything in old dir instead of

View file

@ -68,8 +68,7 @@ Update media table. If file already exists, don't copy."""
# case insensitive filesystems suck # case insensitive filesystems suck
pass pass
else: else:
shutil.copy2(path.encode(sys.getfilesystemencoding()), shutil.copy2(path, new)
new.encode(sys.getfilesystemencoding()))
newSize = os.stat(new)[stat.ST_SIZE] newSize = os.stat(new)[stat.ST_SIZE]
if not deck.s.scalar( if not deck.s.scalar(
"select 1 from media where filename = :f", "select 1 from media where filename = :f",