[Pkg-privacy-commits] [tails-installer] 54/70: Bump the device size requirements and system partition size for new installations (refs: #12707).

Ulrike Uhlig ulrike at moszumanska.debian.org
Mon Nov 20 14:55:01 UTC 2017


This is an automated email from the git hooks/post-receive script.

ulrike pushed a commit to annotated tag tails-installer_4.20
in repository tails-installer.

commit 2a70294a425755d8444635d0b25becef280cac1d
Author: intrigeri <intrigeri at boum.org>
Date:   Tue Sep 12 12:58:48 2017 +0000

    Bump the device size requirements and system partition size for new installations (refs: #12707).
    
    In more details:
    
    1. Refuse installing a new Tails on a stick smaller than 8 GiB, but allow
       upgrading them. This will cause problems at some point, but not right now
       so we'll deal with that later (#14622).
    2. Create bigger system partitions: 4 GiB on devices smaller than "16 GB",
       8 GiB otherwise.
    
    … and while I'm at it, refactor a bit the code I had to touch so that I could
    understand what I was doing.
---
 tails_installer/config.py  | 14 ++++++++++++--
 tails_installer/creator.py | 42 ++++++++++++++++++++++++++++++------------
 tails_installer/gui.py     |  8 +++-----
 tails_installer/utils.py   |  5 +++++
 4 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/tails_installer/config.py b/tails_installer/config.py
index 29f6725..fb03131 100644
--- a/tails_installer/config.py
+++ b/tails_installer/config.py
@@ -9,8 +9,18 @@ config_files = [ os.path.join('/', 'etc', 'tails-installer', f )
 
 # XXX: move defaults to a proper defaults.ini file?
 default_config = {
-    'min_system_partition_size': 2500, # MiB
-    'min_persistence_partition_size': 1000, # MiB
+    # Minimum device size we accept as valid target for initial
+    # installation, in MiB as in 1 MiB = 1024**2 bytes. I've seen USB
+    # sticks labeled "8 GB" that were 7759462400 bytes = 7400 MiB
+    # large, and one can probably fine even smaller ones, so let's be
+    # nice with users who believed what was written on the box and
+    # accept slightly smaller devices than what the theory
+    # would dictate.
+    'min_installation_device_size': 7200,
+    # Minimum device size we tell the user they should get, in MB
+    # as in 1000 MB = 1 GB, i.e. let's use a unit close to what they will
+    # see displayed in shops.
+    'official_min_installation_device_size': 8000,
     'main_liveos_dir': 'live',
     'running_liveos_mountpoint': '/lib/live/mount/medium',
     'tails_vendor_path': '/etc/dpkg/origins/Tails',
diff --git a/tails_installer/creator.py b/tails_installer/creator.py
index 164bb48..de6a4f2 100755
--- a/tails_installer/creator.py
+++ b/tails_installer/creator.py
@@ -49,7 +49,8 @@ if 'linux' in sys.platform:
 from tails_installer.utils import (_move_if_exists, _unlink_if_exists, unicode_to_utf8,
                            unicode_to_filesystemencoding, is_running_from_tails,
                            _set_liberal_perms_recursive, underlying_physical_device,
-                           get_open_write_fd, write_to_block_device)
+                           get_open_write_fd, write_to_block_device,
+                           MiB_to_bytes)
 from tails_installer import _
 from tails_installer.config import config
 from tails_installer.source import SourceError
@@ -71,8 +72,7 @@ class TailsInstallerError(Exception):
 class TailsInstallerCreator(object):
     """ An OS-independent parent class for Tails Installer Creators """
 
-    system_partition_size = config['min_system_partition_size'] # MiB
-    min_persistence_partition_size = config['min_persistence_partition_size'] # MiB
+    min_installation_device_size = config['min_installation_device_size'] # MiB
     source = None       # the object representing our live source image
     label = config['branding']['partition_label'] # if one doesn't already exist
     fstype = None       # the format of our usb stick
@@ -231,11 +231,29 @@ class TailsInstallerCreator(object):
                + [ self.drive['parent'] ])
         self.popen(cmd, shell=False)
 
-    def is_device_big_enough(self, deviceSize):
-        if (self.system_partition_size + self.min_persistence_partition_size) \
-                * 1024**2 <= deviceSize:
-            return True
-        return False
+    def system_partition_size(self, device_size_in_bytes):
+        """ Return the optimal system partition size (in bytes) for
+        a device_size_in_bytes bytes large destination device: 4 GiB on devices
+        smaller than 16000 MiB, 8 GiB otherwise.
+        """
+        # 1. Get unsupported cases out of the way
+        if device_size_in_bytes \
+           < MiB_to_bytes(self.min_installation_device_size):
+            raise NotImplementedError
+        # 2. Handle supported cases (note: you might be surprised if
+        # you looked at the actual size of USB sticks labeled "16 GB"
+        # in the real world, hence the weird definition of "16 GB"
+        # used below)
+        elif device_size_in_bytes >= MiB_to_bytes(14500):
+            return MiB_to_bytes(8 * 1024)
+        else:
+            return MiB_to_bytes(4 * 1024)
+
+    def is_device_big_enough_for_installation(self, device_size_in_bytes):
+        return (
+            device_size_in_bytes
+            >= MiB_to_bytes(self.min_installation_device_size)
+        )
 
     def can_read_partition_table(self, device=None):
         if not device:
@@ -607,7 +625,7 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
                 'parent_size': None,
                 'size': drive.props.size,
                 'mounted_partitions': set(),
-                'is_device_big_enough': True,
+                'is_device_big_enough_for_installation': True,
                 'removable': drive.props.removable,
             }
 
@@ -646,9 +664,9 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
 
             # Check for devices that are too small
             if self.opts.partition and not parent_block \
-                  and not self.is_device_big_enough(data['size']):
+                  and not self.is_device_big_enough_for_installation(data['size']):
                 self.log.warning('Skipping too small device: %s' % data['device'])
-                data['is_device_big_enough'] = False
+                data['is_device_big_enough_for_installation'] = False
 
             mount = data['mount']
             if mount:
@@ -846,7 +864,7 @@ class LinuxTailsInstallerCreator(TailsInstallerCreator):
         try:
             partition_table.call_create_partition_sync(
                     arg_offset=0,
-                    arg_size=self.system_partition_size * 2**20,
+                    arg_size=self.system_partition_size(self.drive['size']),
                     arg_type=ESP_GUID,
                     arg_name=self.label,
                     arg_options=GLib.Variant('a{sv}', None),
diff --git a/tails_installer/gui.py b/tails_installer/gui.py
index 10b75b3..bcf66ef 100755
--- a/tails_installer/gui.py
+++ b/tails_installer/gui.py
@@ -440,8 +440,7 @@ class TailsInstallerWindow(Gtk.ApplicationWindow):
                         _("No device suitable to install Tails could be found"))
                 self.__label_infobar_details.set_text(
                         _("Please plug a USB flash drive or SD card of at least %0.1f GB.")
-                        % ((config['min_system_partition_size'] +
-                            config['min_persistence_partition_size']) / 1000.))
+                        % (config['official_min_installation_device_size'] / 1000.))
                 self.__infobar.set_visible(True)
                 self.target_available = False
                 self.update_start_button()
@@ -494,13 +493,12 @@ class TailsInstallerWindow(Gtk.ApplicationWindow):
                     self.status(message)
                     continue
                 # Skip too small devices, but inform the user
-                if not info['is_device_big_enough']:
+                if not info['is_device_big_enough_for_installation']:
                     message =_('The device "%(pretty_name)s"'
                                ' is too small to install'
                                ' Tails (at least %(size)s GB is required).') %  {
                                'pretty_name':  pretty_name,
-                               'size'  :  (float(config['min_system_partition_size']
-                                       + config['min_persistence_partition_size'])
+                               'size'  :  (float(config['official_min_installation_device_size'])
                                        / 1000)
                                }
                     self.status(message)
diff --git a/tails_installer/utils.py b/tails_installer/utils.py
index f5689ec..bc460f9 100644
--- a/tails_installer/utils.py
+++ b/tails_installer/utils.py
@@ -100,6 +100,11 @@ def underlying_physical_device(path):
 def _format_bytes_in_gb(value):
     return '%0.1f GB' % (value / 10.0**9)
 
+
+def MiB_to_bytes(size_in_MiB):
+    return size_in_MiB * 1024**2
+
+
 def _get_datadir():
     script_path = os.path.abspath(sys.argv[0])
     if not script_path.startswith('/usr/'):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/tails-installer.git



More information about the Pkg-privacy-commits mailing list