From 375e410aa310c24ec0e95ee48ebd40675d5df1e7 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Mon, 15 Jul 2019 14:31:17 +0300 Subject: [PATCH] - /filtering/remove_url: windows: remove filter file only after DNS server has been stopped Otherwise, os.Remove() will return with an error "file is being used". --- home/control.go | 7 +++++++ home/dns.go | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/home/control.go b/home/control.go index 9e06258a..c17771d0 100644 --- a/home/control.go +++ b/home/control.go @@ -722,6 +722,11 @@ func handleFilteringRemoveURL(w http.ResponseWriter, r *http.Request) { return } + // Stop DNS server: + // we close urlfilter object which in turn closes file descriptors to filter files. + // Otherwise, Windows won't allow us to remove the file which is being currently used. + _ = dnsServer.Stop() + // go through each element and delete if url matches config.Lock() newFilters := config.Filters[:0] @@ -732,9 +737,11 @@ func handleFilteringRemoveURL(w http.ResponseWriter, r *http.Request) { // Remove the filter file err := os.Remove(filter.Path()) if err != nil && !os.IsNotExist(err) { + config.Unlock() httpError(w, http.StatusInternalServerError, "Couldn't remove the filter file: %s", err) return } + log.Debug("os.Remove(%s)", filter.Path()) } } // Update the configuration after removing filter files diff --git a/home/dns.go b/home/dns.go index 1f340f91..ae9b8f42 100644 --- a/home/dns.go +++ b/home/dns.go @@ -257,7 +257,7 @@ func startDNSServer() error { func reconfigureDNSServer() error { if !isRunning() { - return fmt.Errorf("Refusing to reconfigure forwarding DNS server: not running") + return nil } config, err := generateServerConfig() @@ -274,7 +274,7 @@ func reconfigureDNSServer() error { func stopDNSServer() error { if !isRunning() { - return fmt.Errorf("Refusing to stop forwarding DNS server: not running") + return nil } err := dnsServer.Stop()