double check that volume is still around, only flag files as missing
This commit is contained in:
parent
ee315399bb
commit
8928b5447b
3 changed files with 66 additions and 14 deletions
|
@ -556,6 +556,11 @@ class Item(db.Model):
|
|||
return True
|
||||
return False
|
||||
|
||||
def missing_file(self):
|
||||
logger.debug('file is missing! %s: %s', self.id, self.get_path())
|
||||
self.info['missing'] = True
|
||||
state.db.session.add(self)
|
||||
|
||||
def remove_file(self):
|
||||
for f in self.files.all():
|
||||
path = f.fullpath()
|
||||
|
|
|
@ -29,10 +29,11 @@ def remove_missing(books=None):
|
|||
dirty = False
|
||||
logger.debug('remove missing')
|
||||
prefix = get_prefix()
|
||||
oml_prefix = os.path.dirname(prefix)
|
||||
if books is None:
|
||||
books = collect_books(prefix)
|
||||
with db.session():
|
||||
if os.path.exists(prefix):
|
||||
if os.path.exists(prefix) and os.path.exists(oml_prefix):
|
||||
logger.debug('scan for removed files')
|
||||
db_paths = []
|
||||
items = {}
|
||||
|
@ -44,27 +45,33 @@ def remove_missing(books=None):
|
|||
if f.item:
|
||||
items[path] = f.sha1
|
||||
else:
|
||||
logger.debug('remove orphaned file %s', f)
|
||||
state.db.session.delete(f)
|
||||
dirty = True
|
||||
if dirty:
|
||||
state.db.session.commit()
|
||||
dirty = False
|
||||
nfd_books = {unicodedata.normalize('NFD', path) for path in books}
|
||||
nfc_books = {unicodedata.normalize('NFC', path) for path in books}
|
||||
removed = [
|
||||
path for path in db_paths
|
||||
if unicodedata.normalize('NFD', path) not in nfd_books
|
||||
if unicodedata.normalize('NFC', path) not in nfc_books
|
||||
]
|
||||
if removed:
|
||||
if removed and os.path.exists(prefix) and os.path.exists(oml_prefix):
|
||||
logger.debug('%s files removed', len(removed))
|
||||
ids = [items[path] for path in removed]
|
||||
if ids:
|
||||
orphaned = set(ids)
|
||||
for i in Item.query.filter(Item.id.in_(ids)):
|
||||
i.remove_file()
|
||||
if state.shutdown:
|
||||
continue
|
||||
i.missing_file()
|
||||
orphaned.remove(i.id)
|
||||
dirty = True
|
||||
if orphaned:
|
||||
logger.debug('%s files orphaned', len(orphaned))
|
||||
for f in File.query.filter(File.sha1.in_(orphaned)):
|
||||
if state.shutdown:
|
||||
continue
|
||||
state.db.session.delete(f)
|
||||
dirty = True
|
||||
if dirty:
|
||||
|
@ -182,6 +189,10 @@ def run_scan():
|
|||
add_record('edititem', item.id, item.meta)
|
||||
item.update()
|
||||
added += 1
|
||||
if file and file.item.info.get('missing'):
|
||||
logger.debug('missing file showed up again %s: %s', id, file.fullpath())
|
||||
del file.item.info['missing']
|
||||
file.item.save()
|
||||
if file and not file.item.added:
|
||||
file.item.added = datetime.utcnow()
|
||||
if file.item.accessed:
|
||||
|
|
|
@ -256,6 +256,42 @@ oml.ui.infoView = function(externalData, isMixed) {
|
|||
],
|
||||
float: 'right'
|
||||
})
|
||||
: data.missing
|
||||
? Ox.FormElementGroup({
|
||||
elements: [
|
||||
Ox.Button({
|
||||
style: 'squared',
|
||||
title: Ox._('Book Missing'),
|
||||
width: 112
|
||||
})
|
||||
.bindEvent({
|
||||
click: function() {
|
||||
if (!oml.readOnly) {
|
||||
oml.api.openFolder({id: oml.user.ui.item});
|
||||
}
|
||||
}
|
||||
}),
|
||||
Ox.MenuButton({
|
||||
items: [
|
||||
].concat(oml.readOnly ? [] : [
|
||||
{id: 'show', title: Ox._('Show File')}
|
||||
]),
|
||||
overlap: 'left',
|
||||
style: 'squared',
|
||||
title: 'select',
|
||||
tooltip: Ox._('File was removed'),
|
||||
type: 'image'
|
||||
})
|
||||
.bindEvent({
|
||||
click: function(data_) {
|
||||
if (!oml.readOnly) {
|
||||
oml.api.openFolder({id: oml.user.ui.item});
|
||||
}
|
||||
}
|
||||
})
|
||||
],
|
||||
float: 'right'
|
||||
})
|
||||
: Ox.FormElementGroup({
|
||||
elements: [
|
||||
Ox.Button({
|
||||
|
|
Loading…
Reference in a new issue