storage/file: get volume size from the actual image file size
Don't realy on a volume configuration only, it's easy to miss updating it. Specifically, import_volume() function didn't updated the size based on the source volume. The size that the actual VM sees is based on the file size, and so is the filesystem inside. Outdated size property can lead to a data loss if the user perform an action based on a incorrect assumption - like extending size, which actually will shrink the volume. Fixes QubesOS/qubes-issues#4821
This commit is contained in:
parent
598d059c57
commit
dd037f4663
@ -28,6 +28,7 @@ import os
|
||||
import os.path
|
||||
import re
|
||||
import subprocess
|
||||
from contextlib import suppress
|
||||
|
||||
import qubes.storage
|
||||
|
||||
@ -394,6 +395,17 @@ class FileVolume(qubes.storage.Volume):
|
||||
iso_date = qubes.storage.isodate(seconds).split('.', 1)[0]
|
||||
return {'old': iso_date}
|
||||
|
||||
@property
|
||||
def size(self):
|
||||
with suppress(FileNotFoundError):
|
||||
self._size = os.path.getsize(self.path)
|
||||
return self._size
|
||||
|
||||
@size.setter
|
||||
def size(self, _):
|
||||
raise qubes.storage.StoragePoolException(
|
||||
"You shouldn't use volume size setter, use resize method instead")
|
||||
|
||||
@property
|
||||
def usage(self):
|
||||
''' Returns the actualy used space '''
|
||||
|
Loading…
Reference in New Issue
Block a user