Skip to content

Commit cb4423b

Browse files
Merge pull request #23 from mstormi/patch-3
fix zram-device-list for multiple starts or stops in a row
2 parents f968616 + 0f145d2 commit cb4423b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Diff for: zram-config

+14-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fi
245245
case "$1" in
246246
start)
247247
echo "zram-config start $(date +%Y-%m-%d-%H:%M:%S)" >>${ZLOG}
248-
rm -f ${ZSHARE}/zram-device-list >>${ZLOG}
248+
rm -f ${ZSHARE}/zram-device-list.new >>${ZLOG}
249249
file=/etc/ztab
250250
ZTAB_EMPTY=true
251251
while read -r line; do
@@ -268,6 +268,18 @@ case "$1" in
268268
ALG=$2
269269
MEM_SIZE=$3
270270
DISK_SIZE=$4
271+
if [ "$1" = "swap" ]; then
272+
entry=$(egrep "^swap" ${ZSHARE}/zram-device-list)
273+
else
274+
entry=$(egrep "$1.*$5" ${ZSHARE}/zram-device-list)
275+
fi
276+
if [ -n "$entry" ]; then
277+
echo "entry $entry already exists as zram."
278+
echo $entry >> ${ZSHARE}/zram-device-list.new
279+
continue
280+
fi
281+
mv ${ZSHARE}/zram-device-list.new ${ZSHARE}/zram-device-list
282+
271283
case "$1" in
272284
swap)
273285
PRIORITY=$5
@@ -346,7 +358,7 @@ case "$1" in
346358
;;
347359
esac
348360
done < "$file"
349-
rm -v ${ZSHARE}/zram-device-list.rev >>${ZLOG}
361+
rm -fv ${ZSHARE}/zram-device-list.rev ${ZSHARE}/zram-device-list >>${ZLOG}
350362
;;
351363

352364
enable-ephemeral)

0 commit comments

Comments
 (0)