From 4bfa6c6c9749fb3d8b73734ec7aa1ca51f813b5f Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 4 Aug 2020 15:24:07 +0200 Subject: [PATCH] Remove temporary files at startup. When something happens while a host config files is written, a temporary file might be left over. Clean these up when we find them when starting MeshLink. --- src/net_setup.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/net_setup.c b/src/net_setup.c index b289a765..269b46ed 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -278,6 +278,15 @@ static bool load_node(meshlink_handle_t *mesh, const char *name, void *priv) { (void)priv; if(!check_id(name)) { + // Check if this is a temporary file, if so remove it + const char *suffix = strstr(name, ".tmp"); + + if(suffix && !suffix[4]) { + char filename[PATH_MAX]; + snprintf(filename, sizeof(filename), "%s" SLASH "current" SLASH "hosts", mesh->confbase); + unlink(filename); + } + return true; } -- 2.39.5