check for contents of bookmark files to improve migration

This commit is contained in:
Jakob Ketterl 2021-04-26 21:05:33 +02:00
parent 7962da9454
commit 5a60869f8e
2 changed files with 12 additions and 6 deletions

View File

@ -7,6 +7,7 @@ OWRX_USER="openwebrx"
OWRX_DATADIR="/var/lib/openwebrx"
OWRX_USERS_FILE="${OWRX_DATADIR}/users.json"
OWRX_SETTINGS_FILE="${OWRX_DATADIR}/settings.json"
OWRX_BOOKMARKS_FILE="${OWRX_DATADIR}/bookmarks.json"
case "$1" in
configure|reconfigure)
@ -17,19 +18,23 @@ case "$1" in
if [ ! -d "${OWRX_DATADIR}" ] && [ ! -L "${OWRX_DATADIR}" ]; then mkdir "${OWRX_DATADIR}"; fi
chown "${OWRX_USER}". ${OWRX_DATADIR}
# create empty config files now to avoid permission problems later
if [ ! -e "${OWRX_USERS_FILE}" ]; then
# create an empty users file now to avoid permission problems later
echo "[]" > "${OWRX_USERS_FILE}"
chown "${OWRX_USER}". "${OWRX_USERS_FILE}"
chmod 0600 "${OWRX_USERS_FILE}"
fi
if [ ! -e "${OWRX_SETTINGS_FILE}" ]; then
# create an empty settings file now to avoid permission problems later
echo "{}" > "${OWRX_SETTINGS_FILE}"
chown "${OWRX_USER}". "${OWRX_SETTINGS_FILE}"
fi
if [ ! -e "${OWRX_BOOKMARKS_FILE}" ]; then
touch "${OWRX_BOOKMARKS_FILE}"
chown "${OWRX_USER}". "${OWRX_BOOKMARKS_FILE}"
fi
db_get openwebrx/admin_user_password
if [ ! -z "${RET}" ]; then
if ! openwebrx admin --silent hasuser admin; then

View File

@ -83,10 +83,11 @@ class Bookmarks(object):
def _loadBookmarks(self):
for file in self.fileList:
try:
f = open(file, "r")
bookmarks_json = json.load(f)
f.close()
return [Bookmark(d) for d in bookmarks_json]
with open(file, "r") as f:
content = f.read()
if content:
bookmarks_json = json.loads(content)
return [Bookmark(d) for d in bookmarks_json]
except FileNotFoundError:
pass
except json.JSONDecodeError: