From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id BDF78138334 for ; Sat, 7 Jul 2018 05:23:57 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6033BE0B3B; Sat, 7 Jul 2018 05:23:55 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 2B061E0AFB for ; Sat, 7 Jul 2018 05:23:55 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 86519335C96 for ; Sat, 7 Jul 2018 05:23:53 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 5FBE1366 for ; Sat, 7 Jul 2018 05:23:50 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1530940931.80a59eed95c17a8702da10f54f9b6fdf8e90a880.dolsen@gentoo> Subject: [gentoo-commits] proj/gentoo-keys:master commit in: gkeys/gkeys/ X-VCS-Repository: proj/gentoo-keys X-VCS-Files: gkeys/gkeys/lock.py X-VCS-Directories: gkeys/gkeys/ X-VCS-Committer: dolsen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 80a59eed95c17a8702da10f54f9b6fdf8e90a880 X-VCS-Branch: master Date: Sat, 7 Jul 2018 05:23:50 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 99c12825-3532-4f1d-9e00-a207aa959e82 X-Archives-Hash: 83a356e3c29406f29950d22b198f4fa3 commit: 80a59eed95c17a8702da10f54f9b6fdf8e90a880 Author: Brian Dolbec gentoo org> AuthorDate: Mon Jul 2 21:52:53 2018 +0000 Commit: Brian Dolbec gentoo org> CommitDate: Sat Jul 7 05:22:11 2018 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=80a59eed gkeys/lock.py: New LockDir class Signed-off-by: Brian Dolbec gentoo.org> gkeys/gkeys/lock.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/gkeys/gkeys/lock.py b/gkeys/gkeys/lock.py new file mode 100644 index 0000000..5614335 --- /dev/null +++ b/gkeys/gkeys/lock.py @@ -0,0 +1,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()