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

@@ -10,6 +10,7 @@ import (
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
"time"
)
@@ -61,6 +62,12 @@ func main() {
}
}()
myLock := "/net/corpora/nlnieuws/Sikkom/lock"
mkLock(myLock)
defer func() {
_ = os.Remove(myLock)
}()
resp, err := http.Get("https://www.sikkom.nl/api/feed/rss")
p(err)
body, err := io.ReadAll(resp.Body)
@@ -242,3 +249,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))
}
}