From 259c938a7796f1aa4a8d2d9477aaed8bc72293e8 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Tue, 14 Jul 2015 21:44:59 +0200 Subject: Bugfix : lstat().st_size always return 0 if a block device is given --- mydisks.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mydisks.py b/mydisks.py index 2a8ae47..4ca21bf 100644 --- a/mydisks.py +++ b/mydisks.py @@ -45,9 +45,9 @@ class MyDisks(): def open_disks(self): """(re)open all disks""" logging.debug("Enter open_disks()") - for fd in self.disks: + for fh in self.disks: try: - fd.close() + fh.close() except: pass self.disks = [ None for d in range(self.disk_count) ] @@ -57,15 +57,19 @@ class MyDisks(): path = self.disk_paths[d] logging.debug("Try to open disk #%2d"%d) try: - self.disks[d] = open(path, "r") - self.disks_size[d] = os.lstat(path).st_size + fh = open(path, "rb") + self.disks_size[d] = os.lseek(fh.fileno(), 0, os.SEEK_END) + self.disks[d] = fh logging.debug("Opened disk #%2d"%d) except IOError as e: logging.error("Can't open disk #%2d ('%s') : %s"%(d, path, e.strerror)) + logging.exception(e) self.disks_size[d] = 0 - except: + except Exception as e: logging.error("Can't open disk #%2d ('%s') : unhandled exception"%(d, path)) self.disks_size[d] = 0 + logging.exception(e) + logging.debug("Exit. open_disks()") -- cgit v1.2.3