1 // Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
2 // All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
14 type plan9FileLock struct {
18 func (fl *plan9FileLock) release() error {
22 func newFileLock(path string, readOnly bool) (fl fileLock, err error) {
31 perm = os.ModeExclusive
33 f, err := os.OpenFile(path, flag, perm)
34 if os.IsNotExist(err) {
35 f, err = os.OpenFile(path, flag|os.O_CREATE, perm|0644)
40 fl = &plan9FileLock{f: f}
44 func rename(oldpath, newpath string) error {
45 if _, err := os.Stat(newpath); err == nil {
46 if err := os.Remove(newpath); err != nil {
51 _, fname := filepath.Split(newpath)
52 return os.Rename(oldpath, fname)
55 func syncDir(name string) error {
56 f, err := os.Open(name)
61 if err := f.Sync(); err != nil {