From 905e325ded05f2fcc6169a6a2fbb316369d9583d Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Mon, 17 Aug 2020 22:55:32 -0400 Subject: [PATCH] fsck: add fixer that fully removes a stream --- nilmdb/fsck/fsck.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/nilmdb/fsck/fsck.py b/nilmdb/fsck/fsck.py index acdd41d..6bb6e55 100644 --- a/nilmdb/fsck/fsck.py +++ b/nilmdb/fsck/fsck.py @@ -328,6 +328,24 @@ class Fsck(object): f.truncate(newsize) raise RetryFsck + def fix_remove_stream(self, sid, path, bulk, reason): + msg = f"stream {path} is corrupted: {reason}" + if not self.fix: + raise FixableFsckError(msg) + # Remove the stream from disk and the database + err(f"\n{msg}\n") + err(f"Removing stream {path} from disk and database\n") + shutil.rmtree(bulk) + with self.sql: + cur = self.sql.cursor() + cur.execute("DELETE FROM streams WHERE id=?", + (sid,)) + if cur.rowcount != 1: # pragma: no cover (shouldn't fail) + raise FsckError("failed to remove stream") + cur.execute("DELETE FROM ranges WHERE stream_id=?", (sid,)) + cur.execute("DELETE FROM metadata WHERE stream_id=?", (sid,)) + raise RetryFsck + ### Check interval endpoints def check_intervals(self):