diff options
author | Ludovic Pouzenc <lpouzenc@gmail.com> | 2015-07-14 21:44:59 +0200 |
---|---|---|
committer | Ludovic Pouzenc <lpouzenc@gmail.com> | 2015-07-14 21:44:59 +0200 |
commit | 259c938a7796f1aa4a8d2d9477aaed8bc72293e8 (patch) | |
tree | 76ec954348cac80e93df9c9d1f1dcafdb679a4a6 | |
parent | 560f4cdf61a0259af57e276e4759d164327882db (diff) | |
download | raidguessfs-259c938a7796f1aa4a8d2d9477aaed8bc72293e8.tar.gz raidguessfs-259c938a7796f1aa4a8d2d9477aaed8bc72293e8.tar.bz2 raidguessfs-259c938a7796f1aa4a8d2d9477aaed8bc72293e8.zip |
Bugfix : lstat().st_size always return 0 if a block device is given
-rw-r--r-- | mydisks.py | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -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()") |