Fixes an issue with completely empty hard drives

If empty hard drives are being set up for the first time, then `.has_content()`'s `mount` call will fail with `wrong fstype` since there's no filesystem yet. First step in this case is to check for that scenario, then check for content.
This commit is contained in:
Anton Hvornum 2021-03-24 15:49:54 +01:00 committed by GitHub
parent 037332a18d
commit 89a2e1eb2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -204,6 +204,9 @@ class Partition():
return None
def has_content(self):
if not get_filesystem_type(self.path):
return False
temporary_mountpoint = '/tmp/'+hashlib.md5(bytes(f"{time.time()}", 'UTF-8')+os.urandom(12)).hexdigest()
temporary_path = pathlib.Path(temporary_mountpoint)
@ -529,4 +532,4 @@ def get_filesystem_type(path):
handle = sys_command(f"blkid -o value -s TYPE {path}")
return b''.join(handle).strip().decode('UTF-8')
except SysCallError:
return None
return None