mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
restore media dir mod check
https://anki.tenderapp.com/discussions/beta-testing/853-anki-210-beta-21/page/1#comment_44071381
This commit is contained in:
parent
8c5abe3a13
commit
5ee1ee0450
1 changed files with 24 additions and 1 deletions
|
@ -121,6 +121,18 @@ create table meta (dirMod int, lastUsn int); insert into meta values (0, 0);
|
||||||
def dir(self):
|
def dir(self):
|
||||||
return self._dir
|
return self._dir
|
||||||
|
|
||||||
|
def _isFAT32(self):
|
||||||
|
if not isWin:
|
||||||
|
return
|
||||||
|
import win32api, win32file
|
||||||
|
try:
|
||||||
|
name = win32file.GetVolumeNameForVolumeMountPoint(self._dir[:3])
|
||||||
|
except:
|
||||||
|
# mapped & unmapped network drive; pray that it's not vfat
|
||||||
|
return
|
||||||
|
if win32api.GetVolumeInformation(name)[4].lower().startswith("fat"):
|
||||||
|
return True
|
||||||
|
|
||||||
# Adding media
|
# Adding media
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# opath must be in unicode
|
# opath must be in unicode
|
||||||
|
@ -353,7 +365,8 @@ create table meta (dirMod int, lastUsn int); insert into meta values (0, 0);
|
||||||
|
|
||||||
def findChanges(self):
|
def findChanges(self):
|
||||||
"Scan the media folder if it's changed, and note any changes."
|
"Scan the media folder if it's changed, and note any changes."
|
||||||
self._logChanges()
|
if self._changed():
|
||||||
|
self._logChanges()
|
||||||
|
|
||||||
def haveDirty(self):
|
def haveDirty(self):
|
||||||
return self.db.scalar("select 1 from media where dirty=1 limit 1")
|
return self.db.scalar("select 1 from media where dirty=1 limit 1")
|
||||||
|
@ -364,6 +377,15 @@ create table meta (dirMod int, lastUsn int); insert into meta values (0, 0);
|
||||||
def _checksum(self, path):
|
def _checksum(self, path):
|
||||||
return checksum(open(path, "rb").read())
|
return checksum(open(path, "rb").read())
|
||||||
|
|
||||||
|
def _changed(self):
|
||||||
|
"Return dir mtime if it has changed since the last findChanges()"
|
||||||
|
# doesn't track edits, but user can add or remove a file to update
|
||||||
|
mod = self.db.scalar("select dirMod from meta")
|
||||||
|
mtime = self._mtime(self.dir())
|
||||||
|
if not self._isFAT32() and mod and mod == mtime:
|
||||||
|
return False
|
||||||
|
return mtime
|
||||||
|
|
||||||
def _logChanges(self):
|
def _logChanges(self):
|
||||||
(added, removed) = self._changes()
|
(added, removed) = self._changes()
|
||||||
media = []
|
media = []
|
||||||
|
@ -374,6 +396,7 @@ create table meta (dirMod int, lastUsn int); insert into meta values (0, 0);
|
||||||
# update media db
|
# update media db
|
||||||
self.db.executemany("insert or replace into media values (?,?,?,?)",
|
self.db.executemany("insert or replace into media values (?,?,?,?)",
|
||||||
media)
|
media)
|
||||||
|
self.db.execute("update meta set dirMod = ?", self._mtime(self.dir()))
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
|
|
||||||
def _changes(self):
|
def _changes(self):
|
||||||
|
|
Loading…
Reference in a new issue