Commit a186ef71 authored by rgaudin's avatar rgaudin
Browse files

Fixed #240: Use safer image sizes

parent 085bf996
2.0-rc12
* macOS binary name (Kiwix Hotspot instead of kiwix-hotspot)
* Safer image sizes based on SD card sizes
2.0-rc11
* Fixed an unmount issue on Linux
......
......@@ -15,6 +15,7 @@ from util import get_free_space_in_dir
from util import human_readable_size, get_cache
from util import CLILogger, b64decode
from util import check_user_inputs
from util import get_adjusted_image_size
import tzlocal
import humanfriendly
......@@ -211,6 +212,8 @@ except Exception:
sys.exit(1)
else:
args.human_size = human_readable_size(args.size, False)
# adjust image size for content
args.output_size = get_adjusted_image_size(args.size)
# check arguments
......@@ -278,14 +281,14 @@ if args.size < base_image_size:
file=sys.stderr)
sys.exit(3)
if args.size < required_image_size:
if args.output_size < required_image_size:
print("image size ({img}) is not large enough for the content ({req})"
.format(img=human_readable_size(args.size, False),
req=human_readable_size(required_image_size, False)),
file=sys.stderr)
sys.exit(3)
if avail_space_in_build_dir < args.size:
if avail_space_in_build_dir < args.output_size:
print("Not enough space available at {dir} ({free}) to build image ({img})"
.format(dir=args.build_dir,
free=human_readable_size(avail_space_in_build_dir),
......
......@@ -20,6 +20,7 @@ from util import get_free_space_in_dir
from util import relpathto
from util import b64encode, b64decode
from util import check_user_inputs
from util import get_adjusted_image_size
import data
import iso639
import requests
......@@ -1215,7 +1216,7 @@ class Application:
size = int(self.component.sd_card_list_store[sd_card_id][get_size_index])
else:
try:
size = data.sdcard_sizes[self.component.size_combobox.get_active()] * ONE_GB
size = get_adjusted_image_size(data.sdcard_sizes[self.component.size_combobox.get_active()] * ONE_GB)
except Exception:
size = -1
......
......@@ -455,3 +455,17 @@ def check_user_inputs(project_name, language, timezone,
return valid_project_name, valid_language, valid_timezone, \
valid_wifi_pwd, valid_admin_login, valid_admin_pwd
def get_adjusted_image_size(size):
''' save some space to accomodate real SD card sizes
the larger the SD card, the larger the loss space is '''
if size / ONE_GB <= 16:
rate = .98
elif size / ONE_GB <= 64:
rate = .97
else:
rate = .96
return int(size * rate)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment