summaryrefslogtreecommitdiff
path: root/vendor/github.com/mitchellh/packer/builder/amazon/chroot/lockfile_unix.go
blob: 0d0f8c8f7a22f872dcd64eb856a7e53ad10a2f18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// +build !windows

package chroot

import (
	"os"

	"golang.org/x/sys/unix"
)

// See: http://linux.die.net/include/sys/file.h
const LOCK_EX = 2
const LOCK_NB = 4
const LOCK_UN = 8

func lockFile(f *os.File) error {
	err := unix.Flock(int(f.Fd()), LOCK_EX)
	if err != nil {
		return err
	}

	return nil
}

func unlockFile(f *os.File) error {
	return unix.Flock(int(f.Fd()), LOCK_UN)
}