aboutsummaryrefslogtreecommitdiff
blob: 5614335bd454f600d1ec0f872caa563243bdec64 (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
28
29
30
31
import os

from snakeoil import fileutils
from snakeoil import osutils
from catalyst.fileops import ensure_dirs


LockInUse = osutils.LockException


class LockDir(object):
    """An object that creates locks inside dirs"""

    def __init__(self, lockdir):
        #self.gid = 250
        self.lockfile = os.path.join(lockdir, '.gkeys_lock')
        ensure_dirs(lockdir)
        fileutils.touch(self.lockfile, mode=0o664)
        #os.chown(self.lockfile, -1, self.gid)
        self.lock = osutils.FsLock(self.lockfile)

    def read_lock(self):
        self.lock.acquire_read_lock()

    def write_lock(self):
        self.lock.acquire_write_lock()

    def unlock(self):
        # Releasing a write lock is the same as a read lock.
        self.lock.release_write_lock()