diff --git a/debian/openwebrx.postinst b/debian/openwebrx.postinst index aa57b6e..2ad8e3c 100755 --- a/debian/openwebrx.postinst +++ b/debian/openwebrx.postinst @@ -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 diff --git a/owrx/bookmarks.py b/owrx/bookmarks.py index 39b3a3d..90819bd 100644 --- a/owrx/bookmarks.py +++ b/owrx/bookmarks.py @@ -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: