summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-03-15 10:27:20 +0100
committerSimon Rettberg2019-03-15 10:27:20 +0100
commitcd69c29733d65b6b5948a9cc9fb9e252653bc289 (patch)
tree4125aca5f3b40149ad6d0b4a6b9ab4ab491a4402
parentSimplify checks, consider zram as volatile too (diff)
downloadslx-tools-cd69c29733d65b6b5948a9cc9fb9e252653bc289.tar.gz
slx-tools-cd69c29733d65b6b5948a9cc9fb9e252653bc289.tar.xz
slx-tools-cd69c29733d65b6b5948a9cc9fb9e252653bc289.zip
Invert logic and use || for $x = ${x#<prefix>} checks
This makes it so that if $x starts with <prefix>, the statement after the condition is executed, which seems easier to read. i.e. [ "$x" = "${x#abc}" ] || echo "x starts with abc"
-rw-r--r--slx-tools6
1 files changed, 3 insertions, 3 deletions
diff --git a/slx-tools b/slx-tools
index 5fc1303..972975c 100644
--- a/slx-tools
+++ b/slx-tools
@@ -29,8 +29,8 @@ is_volatile() {
[ -z "$1" ] && return 2
local _dev="$(get_backing_dev "$1")"
[ -z "$_dev" ] && return 0 # No result, assume tmpfs
- [ "$_dev" = "${_dev#/dev/zram}" ] && return 0 # zram is in RAM, like tmpfs
- [ "$_dev" = "${_dev#/dev/mapper/}" ] && return 1 # Doesn't start with /dev/mapper, assume some kind of storage
+ [ "$_dev" = "${_dev#/dev/zram}" ] || return 0 # zram is in RAM, like tmpfs
+ [ "$_dev" != "${_dev#/dev/mapper/}" ] || return 1 # Doesn't start with /dev/mapper, assume some kind of storage
local _mp="$(get_backing_dev_mp "$1")"
[ -z "$_mp" ] && return 2
# it is a device mapper device, check if it was setup in dracut's initramfs.
@@ -44,7 +44,7 @@ is_volatile() {
get_dm_backing_size() {
[ -z "$1" ] && return 1
local _dev="$(get_backing_dev $1)"
- [ "$_dev" = "${_dev#/dev/mapper/}" ] && return 1
+ [ "$_dev" != "${_dev#/dev/mapper/}" ] || return 1 # doesn't start with /dev/mapper, assume not device mapped
local _dm_line="$(grep -m1 -E "^${_dev}\s+/\s+type=[^0]" "$dmstate")"
[ -z "$_dm_line" ] && return 1
local _dm_dev_size="$(echo "$_dm_line" | grep -Po '(?<=physical_size=|virtual_size=)\w*' )"