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 648DF138334 for ; Mon, 18 Feb 2019 16:57:32 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7BDA8E08AB; Mon, 18 Feb 2019 16:57:31 +0000 (UTC) Received: from smtp.gentoo.org (mail.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 4A35AE08AB for ; Mon, 18 Feb 2019 16:57:31 +0000 (UTC) Received: from professor-x (d108-172-195-239.bchsia.telus.net [108.172.195.239]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dolsen) by smtp.gentoo.org (Postfix) with ESMTPSA id 7D1E3335C8F for ; Mon, 18 Feb 2019 16:57:29 +0000 (UTC) Date: Mon, 18 Feb 2019 08:57:30 -0800 From: Brian Dolbec To: gentoo-portage-dev@lists.gentoo.org Subject: Re: [gentoo-portage-dev] [PATCH] locks: handle sshfs hardlink inode numbers (bug 678218) Message-ID: <20190218085730.6fe4a2d9@professor-x> In-Reply-To: <20190217230429.8076-1-zmedico@gentoo.org> References: <20190217230429.8076-1-zmedico@gentoo.org> X-Mailer: Claws Mail 3.17.2 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archives-Salt: f7d81612-eb67-4346-a94d-7dd69b8e6a9b X-Archives-Hash: 93b7f70fd61a8d87bd8788d760a49558 On Sun, 17 Feb 2019 15:04:29 -0800 Zac Medico wrote: > Since hardlinks on sshfs do not have matching inode numbers, detect > this behavior and use a simple stat call to detect if lock_path has > been removed. > > Bug: https://bugs.gentoo.org/678218 > Signed-off-by: Zac Medico > --- > lib/portage/locks.py | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/lib/portage/locks.py b/lib/portage/locks.py > index 74c2c086a..510925da0 100644 > --- a/lib/portage/locks.py > +++ b/lib/portage/locks.py > @@ -340,6 +340,33 @@ def _lockfile_was_removed(lock_fd, lock_path): > > hardlink_stat = os.stat(hardlink_path) > if hardlink_stat.st_ino != fstat_st.st_ino or > hardlink_stat.st_dev != fstat_st.st_dev: > + # Create another hardlink in order to detect > whether or not > + # hardlink inode numbers are expected to > match. For example, > + # inode numbers are not expected to match > for sshfs. > + inode_test = hardlink_path + '-inode-test' > + try: > + os.unlink(inode_test) > + except OSError as e: > + if e.errno not in (errno.ENOENT, > errno.ESTALE): > + _raise_exc(e) > + try: > + os.link(hardlink_path, inode_test) > + except OSError as e: > + if e.errno not in (errno.ENOENT, > errno.ESTALE): > + _raise_exc(e) > + return True > + else: > + if not > os.path.samefile(hardlink_path, inode_test): > + # This implies that inode > numbers are not expected > + # to match for this file > system, so use a simple > + # stat call to detect if > lock_path has been removed. > + return not > os.path.exists(lock_path) > + finally: > + try: > + os.unlink(inode_test) > + except OSError as e: > + if e.errno not in > (errno.ENOENT, errno.ESTALE): > + _raise_exc(e) > return True > finally: > try: Looks fine to me