From 06baaa9f7c037d2aa9d9c67e0b9b07724372e0f0 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 28 Apr 2017 12:02:48 +0100 Subject: Core hotlist: A NULL save_path makes the hotlist read-only. --- desktop/hotlist.c | 19 ++++++++++++++----- desktop/hotlist.h | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/desktop/hotlist.c b/desktop/hotlist.c index 3e2fcedd5..0f5be77c9 100644 --- a/desktop/hotlist.c +++ b/desktop/hotlist.c @@ -107,7 +107,7 @@ static nserror hotlist_get_temp_path(const char *path, char **temp_path) /* Save the hotlist to to a file at the given path * - * \param path Path to save hostlist file to. + * \param path Path to save hotlist file to. NULL path is a no-op. * \return NSERROR_OK on success, or appropriate error otherwise */ static nserror hotlist_save(const char *path) @@ -115,6 +115,11 @@ static nserror hotlist_save(const char *path) nserror res = NSERROR_OK; char *temp_path; + /* NULL path is a no-op. */ + if (path == NULL) { + return NSERROR_OK; + } + /* Get path to export to */ res = hotlist_get_temp_path(path, &temp_path); if (res != NSERROR_OK) { @@ -163,7 +168,7 @@ static void hotlist_schedule_save_cb(void *p) */ static nserror hotlist_schedule_save(void) { - if (hl_ctx.save_scheduled == false) { + if (hl_ctx.save_scheduled == false && hl_ctx.save_path != NULL) { nserror err = guit->misc->schedule(10 * 1000, hotlist_schedule_save_cb, NULL); if (err != NSERROR_OK) { @@ -1285,9 +1290,13 @@ nserror hotlist_init( hl_ctx.default_folder = NULL; /* Store the save path */ - hl_ctx.save_path = strdup(save_path); - if (hl_ctx.save_path == NULL) { - return NSERROR_NOMEM; + if (save_path != NULL) { + hl_ctx.save_path = strdup(save_path); + if (hl_ctx.save_path == NULL) { + return NSERROR_NOMEM; + } + } else { + hl_ctx.save_path = NULL; } /* Init. hotlist treeview entry fields */ diff --git a/desktop/hotlist.h b/desktop/hotlist.h index e38eac1c2..a16b3e8ad 100644 --- a/desktop/hotlist.h +++ b/desktop/hotlist.h @@ -41,7 +41,7 @@ struct rect; * hotlist can be queried to ask if URLs are present in the hotlist. * * \param load_path The path to load hotlist from. - * \param save_path The path to save hotlist to. + * \param save_path The path to save hotlist to, or NULL for read-only. * \return NSERROR_OK on success, appropriate error otherwise */ nserror hotlist_init( -- cgit v1.2.3