lockfiles
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -76,6 +77,12 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
myLock := "/net/corpora/nlnieuws/VRT/lock"
|
||||
mkLock(myLock)
|
||||
defer func() {
|
||||
_ = os.Remove(myLock)
|
||||
}()
|
||||
|
||||
resp, err := http.Get("https://www.vrt.be/vrtnws/nl.rss.headlines.xml")
|
||||
p(err)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
@@ -323,3 +330,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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user