lockfiles

This commit is contained in:
Peter Kleiweg
2026-03-19 14:42:35 +01:00
parent 025c134c07
commit 6d15441a5a
11 changed files with 221 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
"time"
)
@@ -62,6 +63,12 @@ func main() {
}
}()
myLock := "/net/corpora/nlnieuws/NieuwsNL/lock"
mkLock(myLock)
defer func() {
_ = os.Remove(myLock)
}()
req, err := http.NewRequest("GET", "https://nieuws.nl/sitemap/news.xml", nil)
p(err)
req.Header.Set("User-Agent", agent)
@@ -230,3 +237,16 @@ func addEnd(s string) string {
func fixSpace(s string) string {
return strings.Join(strings.Fields(s), " ")
}
func mkLock(filename string) {
pid := os.Getpid()
link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid)
p(os.Symlink(link, filename))
name, err := os.Readlink(filename)
p(err)
if name != link {
p(fmt.Errorf("wrong lock name %q, should be %q", name, link))
}
}