X-Git-Url: http://git.giacomolli.uk/onechat/blobdiff_plain/feda522eba3e2a27c91741c77d0d01f1840c0004..7b6d0a81e0f3c8e33b1b76d5ecbc5bdb25a87249:/log.go diff --git a/log.go b/log.go index dfb6e70..c3d7190 100644 --- a/log.go +++ b/log.go @@ -7,14 +7,10 @@ import ( "fmt" "os" "path/filepath" - "syscall" "time" "unicode/utf8" ) -// errLocked tells that another process owns the chat. -var errLocked = errors.New("another process owns the chat") - // kinds holds the kinds that a message can have. var kinds = map[string]bool{ "user": true, @@ -250,23 +246,3 @@ func validateMessage(message Message) error { return nil } - -// lockFile opens the file at path and takes an exclusive lock on it. The lock -// stays until the file closes or the process ends. -func lockFile(path string) (*os.File, error) { - file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0o600) - if err != nil { - return nil, fmt.Errorf("open lock file: %w", err) - } - - err = syscall.Flock(int(file.Fd()), syscall.LOCK_EX|syscall.LOCK_NB) - if errors.Is(err, syscall.EWOULDBLOCK) { - err = errLocked - } - - if err != nil { - return nil, errors.Join(fmt.Errorf("lock chat: %w", err), file.Close()) - } - - return file, nil -}