Skip to content

Commit

Permalink
fix: 处于“待扫描”状态的记录重启后会继续处理 issue #316
Browse files Browse the repository at this point in the history
  • Loading branch information
talebook committed Dec 29, 2023
1 parent 541874d commit ff95c9c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
28 changes: 28 additions & 0 deletions tests/test_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,34 @@ def test_import_status(self):
self.assertEqual(d["err"], "ok")


class TestScanContinue(TestWithUserLogin):
NEW_ROW_ID = 69

def setUp(self):
# 将这行记录设置为可导入的状态
self.session = self.get_app().settings["ScopedSession"]
self.session.rollback()

row = self.session.query(ScanFile).filter(ScanFile.id == self.NEW_ROW_ID).one()
row.path = testdir + "/cases/new.epub"
row.status = ScanFile.NEW
row.book_id = 0
row.import_id = 0
row.save()
self.session.commit()
return super().setUp()

@mock.patch("webserver.handlers.scan.Scanner.allow_backgrounds")
def test_scan(self, m1):
m1.return_value = False
d = self.json("/api/admin/scan/run", method="POST", body="")
self.assertEqual(d["err"], "ok")

row = self.session.query(ScanFile).filter(ScanFile.id == self.NEW_ROW_ID).one()
self.assertEqual(row.status, ScanFile.READY)



class TestImport(TestWithUserLogin):
READY_ROW_ID = 69

Expand Down
9 changes: 7 additions & 2 deletions webserver/handlers/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@ def do_scan(self, path_dir):
inserted_hash = set()
for fname, fpath, fmt in tasks:
# logging.info("Scan: %s", fpath)
if self.session.query(ScanFile).filter(ScanFile.path == fpath).count() > 0:
samefiles = self.session.query(ScanFile).filter(ScanFile.path == fpath)
if samefiles.count() > 0:
# 如果已经有相同的文件记录,则跳过
continue
row = samefiles.first()
if row.status == ScanFile.NEW:
rows.append( row )
else:
continue

stat = os.stat(fpath)
md5 = hashlib.md5(fname.encode("UTF-8")).hexdigest()
Expand Down

0 comments on commit ff95c9c

Please sign in to comment.