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:
# file-backed
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:
try:
os.mkdir(dir)
@ -1391,10 +1394,9 @@ Return new path, relative to media dir."""
def renameMediaDir(self, oldPath):
"Copy oldPath to our current media dir. "
assert os.path.exists(oldPath)
newPath = self.mediaDir(create=True)
newPath = self.mediaDir(create=None)
# copytree doesn't want the dir to exist
try:
os.rmdir(newPath)
shutil.copytree(oldPath, newPath)
except:
# 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
pass
else:
shutil.copy2(path.encode(sys.getfilesystemencoding()),
new.encode(sys.getfilesystemencoding()))
shutil.copy2(path, new)
newSize = os.stat(new)[stat.ST_SIZE]
if not deck.s.scalar(
"select 1 from media where filename = :f",