helperfuncties naar internal/util (2)

This commit is contained in:
Peter Kleiweg
2026-05-24 16:29:56 +02:00
parent 75832c3132
commit fcad105a75
14 changed files with 37 additions and 125 deletions

View File

@@ -3,6 +3,8 @@ package main
import (
e "codeberg.org/pebbe/errors"
u "git.web.rug.nl/p209327/nlnieuws/internal/util"
"encoding/xml"
"fmt"
"html"
@@ -10,7 +12,6 @@ import (
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
"time"
)
@@ -62,7 +63,7 @@ func main() {
}()
myLock := "/net/corpora/nlnieuws/NOS/lock"
mkLock(myLock)
u.MkLock(myLock)
defer func() {
_ = os.Remove(myLock)
}()
@@ -194,16 +195,3 @@ func doArticle(filename string, url string, timestamp time.Time, needUpdate bool
p(os.Chtimes(filename+".json", timestamp, timestamp))
return true
}
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))
}
}