WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 32cc0df

Browse files
committed
feat(update): make use of flock
Signed-off-by: Tianling Shen <[email protected]>
1 parent 5246155 commit 32cc0df

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ include $(TOPDIR)/rules.mk
77
LUCI_TITLE:=LuCI support for UnblockNeteaseMusic (JavaScript)
88
LUCI_DEPENDS:=+dnsmasq-full +node \
99
+PACKAGE_firewall:ipset \
10+
+@BUSYBOX_CONFIG_FLOCK \
1011
@(PACKAGE_libustream-mbedtls||PACKAGE_libustream-openssl||PACKAGE_libustream-wolfssl)
1112
LUCI_PKGARCH:=all
1213

root/usr/share/unblockneteasemusic/update.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ LOCK="$RUN_DIR/update_core.lock"
1111
LOG="$RUN_DIR/run.log"
1212

1313
check_core_if_already_running() {
14-
if [ -e "$LOCK" ]; then
14+
exec 200>"$LOCK"
15+
16+
if ! flock -n 200 &> /dev/null; then
1517
echo -e "\nA task is already running." >> "$LOG"
1618
exit 2
17-
else
18-
touch "$LOCK"
1919
fi
2020
}
2121

@@ -25,7 +25,7 @@ clean_log(){
2525

2626
check_core_latest_version() {
2727
core_latest_ver="$(wget -qO- 'https://api.github.com/repos/UnblockNeteaseMusic/server/commits?sha=enhanced&path=precompiled' | jsonfilter -e '@[0].sha')"
28-
[ -n "$core_latest_ver" ] || { echo -e "\nFailed to check latest core version, please try again later." >> "$LOG"; rm -f "$LOCK"; exit 1; }
28+
[ -n "$core_latest_ver" ] || { echo -e "\nFailed to check latest core version, please try again later." >> "$LOG"; exit 1; }
2929
if [ ! -e "$UNM_DIR/core_local_ver" ]; then
3030
clean_log
3131
echo -e "Local version: NOT FOUND, latest version: $core_latest_ver." >> "$LOG"
@@ -38,7 +38,6 @@ check_core_latest_version() {
3838
else
3939
echo -e "\nLocal version: $(cat $UNM_DIR/core_local_ver 2>"/dev/null"), latest version: $core_latest_ver." >> "$LOG"
4040
echo -e "You're already using the latest version." >> "$LOG"
41-
rm -f "$LOCK"
4241
exit 3
4342
fi
4443
fi
@@ -55,7 +54,6 @@ update_core() {
5554
wget "https://fastly.jsdelivr.net/gh/UnblockNeteaseMusic/server@$core_latest_ver/$file" -qO "$UNM_DIR/core/${file##*/}"
5655
[ -s "$UNM_DIR/core/${file##*/}" ] || {
5756
echo -e "Failed to download ${file##*/}." >> "$LOG"
58-
rm -f "$LOCK"
5957
exit 1
6058
}
6159
done
@@ -65,7 +63,6 @@ update_core() {
6563
wget "https://fastly.jsdelivr.net/gh/UnblockNeteaseMusic/server@$core_latest_ver/$cert" -qO "$UNM_DIR/core/$cert"
6664
[ -s "$UNM_DIR/core/${cert}" ] || {
6765
echo -e "Failed to download ${cert}." >> "$LOG"
68-
rm -f "$LOCK"
6966
exit 1
7067
}
7168
done
@@ -75,7 +72,6 @@ update_core() {
7572

7673
echo -e "Succeeded in updating core." > "$LOG"
7774
echo -e "Current core version: $core_latest_ver.\n" >> "$LOG"
78-
rm -f "$LOCK"
7975
}
8076

8177
case "$1" in

0 commit comments

Comments
 (0)