mirror of
https://github.com/ankitects/anki.git
synced 2025-11-14 08:37:11 -05:00
fix media dir problem on win32, fix unicode issues with media
This commit is contained in:
parent
2aecbffafe
commit
7e74fe3844
2 changed files with 5 additions and 4 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue