fix backup on win32

This commit is contained in:
Damien Elmes 2009-01-05 06:51:47 +09:00
parent 8750b9bbbb
commit 2aecbffafe

View file

@ -2184,23 +2184,17 @@ where interval < 1""")
_setUTCOffset = staticmethod(_setUTCOffset) _setUTCOffset = staticmethod(_setUTCOffset)
def backup(modified, path): def backup(modified, path):
try:
os.makedirs(backupDir)
except OSError:
pass
# need a non-unicode path # need a non-unicode path
path = path.encode(sys.getfilesystemencoding())
bdir = backupDir.encode(sys.getfilesystemencoding())
def backupName(path, num): def backupName(path, num):
path = os.path.abspath(path) path = os.path.abspath(path)
path = path.replace("\\", "!") path = path.replace("\\", "!")
path = path.replace("/", "!") path = path.replace("/", "!")
path = path.replace(":", "") path = path.replace(":", "")
path = os.path.join(bdir, path) path = os.path.join(backupDir, path)
path = re.sub("\.anki$", ".backup-%d.anki" % num, path) path = re.sub("\.anki$", ".backup-%d.anki" % num, path)
return path return path
if not os.path.exists(bdir): if not os.path.exists(backupDir):
os.makedirs(bdir) os.makedirs(backupDir)
# if the mod time is identical, don't make a new backup # if the mod time is identical, don't make a new backup
firstBack = backupName(path, 0) firstBack = backupName(path, 0)
if os.path.exists(firstBack): if os.path.exists(firstBack):