diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2013-06-06 12:12:57 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2013-06-07 12:20:23 +0000 |
commit | 7fcc0a0afa714b9f731fb3e55ff19f5e632fbb2c (patch) | |
tree | fee4e2bf3c54a8add44f9e823a3a7b3836902ec1 /morphlib/util.py | |
parent | 5baf11496d4f84fa54ec5ff2a5d5464caaaf1492 (diff) | |
download | morph-7fcc0a0afa714b9f731fb3e55ff19f5e632fbb2c.tar.gz |
util: split out space unify logic
Diffstat (limited to 'morphlib/util.py')
-rw-r--r-- | morphlib/util.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/morphlib/util.py b/morphlib/util.py index 1a347da0..6dcb22b5 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -237,16 +237,29 @@ def on_same_filesystem(path_a, path_b): # pragma: no cover # TODO: return true if one path is a subvolume of the other on btrfs? return os.stat(path_a).st_dev == os.stat(path_b).st_dev +def unify_space_requirements(tmp_path, tmp_min_size, + cache_path, cache_min_size): # pragma: no cover + """Adjust minimum sizes when paths share a disk. + + Given pairs of path and minimum size, return the minimum sizes such + that when the paths are on the same disk, the sizes are added together. + + """ + # TODO: make this work for variable number of (path, size) pairs as needed + # hint: try list.sort and itertools.groupby + if not on_same_filesystem(tmp_path, cache_path): + return tmp_min_size, cache_min_size + unified_size = tmp_min_size + cache_min_size + return unified_size, unified_size + def check_disk_available(tmp_path, tmp_min_size, cache_path, cache_min_size): # pragma: no cover # if both are on the same filesystem, assume they share a storage pool, # so the sum of the two sizes needs to be available - # TODO: if we need to do this on any more than 2 filesystems - # extend it to take a [(path, min)] and do some arcane mathematics - # to split it into groups that share a filesystem - # hint: try list.sort and itertools.groupby - if on_same_filesystem(tmp_path, cache_path): - tmp_min_size = cache_min_size = tmp_min_size + cache_min_size + # TODO: if we need to do this on any more than 2 paths + # extend it to take a [(path, min)] + tmp_min_size, cache_min_size = unify_space_requirements( + tmp_path, tmp_min_size, cache_path, cache_min_size) tmp_size, cache_size = map(get_bytes_free_in_path, (tmp_path, cache_path)) errors = [] for path, min in [(tmp_path, tmp_min_size), (cache_path, cache_min_size)]: |