X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lock.go;h=fbdd826caef747572759d798da1503c5a49db9b1;hb=HEAD;hp=271b39cab6527b376a76df0b07a11ba03f16197a;hpb=e011d6f52f2e39006d8a4398ff846f4951b8290c;p=mmc.git diff --git a/lock.go b/lock.go deleted file mode 100644 index 271b39c..0000000 --- a/lock.go +++ /dev/null @@ -1,49 +0,0 @@ -// mmc -- Mattermost client -// Copyright (C) 2023 Sergey Matveev -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 of the -// License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package mmc - -import ( - "io" - "os" - - "golang.org/x/sys/unix" -) - -func Lock(what string) (func(), error) { - fd, err := os.OpenFile( - what, - os.O_WRONLY|os.O_TRUNC|os.O_CREATE, - os.FileMode(0666), - ) - dummy := func() {} - if err != nil { - return dummy, err - } - flock := unix.Flock_t{ - Type: unix.F_WRLCK, - Whence: io.SeekStart, - } - if err = unix.FcntlFlock(fd.Fd(), unix.F_SETLKW, &flock); err != nil { - fd.Close() - return dummy, err - } - return func() { - flock.Type = unix.F_UNLCK - unix.FcntlFlock(fd.Fd(), unix.F_SETLK, &flock) - fd.Close() - }, nil -}