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 EED2A138350 for ; Thu, 30 Apr 2020 22:56:26 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0E2AAE096C; Thu, 30 Apr 2020 22:56:25 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (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 B6E15E096C for ; Thu, 30 Apr 2020 22:56:24 +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 B392134F0C3 for ; Thu, 30 Apr 2020 22:56:23 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 6B8391F2 for ; Thu, 30 Apr 2020 22:56:22 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1587666035.562a9dddee7038804e6c17d8da79262ad45deaf5.mattst88@gentoo> Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/lock.py X-VCS-Directories: catalyst/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: 562a9dddee7038804e6c17d8da79262ad45deaf5 X-VCS-Branch: master Date: Thu, 30 Apr 2020 22:56:22 +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-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 2f7385d6-ed75-4e3d-a362-8d3a94520da3 X-Archives-Hash: e7dbe43e8391f3334e0cb1f193946260 commit: 562a9dddee7038804e6c17d8da79262ad45deaf5 Author: Matt Turner gentoo org> AuthorDate: Sat Apr 18 01:27:31 2020 +0000 Commit: Matt Turner gentoo org> CommitDate: Thu Apr 23 18:20:35 2020 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=562a9ddd catalyst: Add a Lock class and refactor LockDir This allows us to make lock files directly. Signed-off-by: Matt Turner gentoo.org> catalyst/lock.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/catalyst/lock.py b/catalyst/lock.py index 5e039fae..ab005163 100644 --- a/catalyst/lock.py +++ b/catalyst/lock.py @@ -8,17 +8,14 @@ from catalyst.fileops import ensure_dirs LockInUse = osutils.LockException - -class LockDir(): - """An object that creates locks inside dirs""" - - def __init__(self, lockdir): - self.gid = 250 - self.lockfile = os.path.join(lockdir, '.catalyst_lock') - ensure_dirs(lockdir) - fileutils.touch(self.lockfile, mode=0o664) - os.chown(self.lockfile, -1, self.gid) - self.lock = osutils.FsLock(self.lockfile) +class Lock: + """ + A fnctl-based filesystem lock + """ + def __init__(self, lockfile): + fileutils.touch(lockfile, mode=0o664) + os.chown(lockfile, uid=-1, gid=250) + self.lock = osutils.FsLock(lockfile) def read_lock(self): self.lock.acquire_read_lock() @@ -29,3 +26,13 @@ class LockDir(): def unlock(self): # Releasing a write lock is the same as a read lock. self.lock.release_write_lock() + +class LockDir(Lock): + """ + A fnctl-based filesystem lock in a directory + """ + def __init__(self, lockdir): + ensure_dirs(lockdir) + lockfile = os.path.join(lockdir, '.catalyst_lock') + + Lock.__init__(self, lockfile)