zoukankan      html  css  js  c++  java
  • dirlock.go

    // +build !windows

    package dirlock

    import (
        "fmt"
        "os"
        "syscall"
    )

    type DirLock struct {
        dir string
        f   *os.File
    }

    func New(dir string) *DirLock {
        return &DirLock{
            dir: dir,
        }
    }

    func (l *DirLock) Lock() error {
        f, err := os.Open(l.dir)
        if err != nil {
            return err
        }
        l.f = f
        err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB)
        if err != nil {
            return fmt.Errorf("cannot flock directory %s - %s", l.dir, err)
        }
        return nil
    }

    func (l *DirLock) Unlock() error {
        defer l.f.Close()
        return syscall.Flock(int(l.f.Fd()), syscall.LOCK_UN)
    }

  • 相关阅读:
    upload.go
    heartbeat.go
    delete.go
    get.go
    handler.go
    uuid.go
    kingpin_parser.go
    disk.go
    logrus_hook.go
    反连接NOT EXISTS子查询中有or 谓词连接条件SQL优化一例
  • 原文地址:https://www.cnblogs.com/zhangboyu/p/7457389.html
Copyright © 2011-2022 走看看