From 796e6f509673f617faf5f2226c3d8d0732375839 Mon Sep 17 00:00:00 2001 From: Rusty Bird Date: Fri, 29 Jan 2021 18:13:29 +0000 Subject: [PATCH] storage/file: refactor is_dirty() --- qubes/storage/file.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/qubes/storage/file.py b/qubes/storage/file.py index c2374272..596f6ed1 100644 --- a/qubes/storage/file.py +++ b/qubes/storage/file.py @@ -214,11 +214,10 @@ class FileVolume(qubes.storage.Volume): _remove_if_exists(self.path_cow) def is_dirty(self): - if not self.save_on_stop: - return False - if os.path.exists(self.path_cow): - stat = os.stat(self.path_cow) - return stat.st_blocks > 0 + if self.save_on_stop: + with suppress(FileNotFoundError), open(self.path_cow, 'rb') as cow: + cow_used = os.fstat(cow.fileno()).st_blocks * BLKSIZE + return cow_used > 0 return False def resize(self, size):