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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id EBADC158089 for ; Wed, 4 Oct 2023 03:25:40 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 30BCF2BC024; Wed, 4 Oct 2023 03:25:40 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 1BA5A2BC024 for ; Wed, 4 Oct 2023 03:25:40 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5E822335C39 for ; Wed, 4 Oct 2023 03:25:39 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id BACA9921 for ; Wed, 4 Oct 2023 03:25:37 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1696388832.3dfe5e326eaaca877bc7a45ec84d6b39fc8d137a.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/util/_async/ X-VCS-Repository: proj/portage X-VCS-Files: lib/portage/util/_async/FileDigester.py X-VCS-Directories: lib/portage/util/_async/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 3dfe5e326eaaca877bc7a45ec84d6b39fc8d137a X-VCS-Branch: master Date: Wed, 4 Oct 2023 03:25:37 +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: 48996d1f-978c-4776-9fe9-9ea298c474b5 X-Archives-Hash: 5374da853fb7056bce02fba548f487c1 commit: 3dfe5e326eaaca877bc7a45ec84d6b39fc8d137a Author: Zac Medico gentoo org> AuthorDate: Wed Oct 4 02:56:10 2023 +0000 Commit: Zac Medico gentoo org> CommitDate: Wed Oct 4 03:07:12 2023 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=3dfe5e32 FileDigester: Migrate to AsyncFunction Bug: https://bugs.gentoo.org/915099 Signed-off-by: Zac Medico gentoo.org> lib/portage/util/_async/FileDigester.py | 71 +++++---------------------------- 1 file changed, 11 insertions(+), 60 deletions(-) diff --git a/lib/portage/util/_async/FileDigester.py b/lib/portage/util/_async/FileDigester.py index ce334ee95a..6491423ae4 100644 --- a/lib/portage/util/_async/FileDigester.py +++ b/lib/portage/util/_async/FileDigester.py @@ -1,13 +1,13 @@ -# Copyright 2013 Gentoo Foundation +# Copyright 2013-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 -from portage import os +import functools + from portage.checksum import perform_multiple_checksums -from portage.util._async.ForkProcess import ForkProcess -from _emerge.PipeReader import PipeReader +from portage.util._async.AsyncFunction import AsyncFunction -class FileDigester(ForkProcess): +class FileDigester(AsyncFunction): """ Asynchronously generate file digests. Pass in file_path and hash_names, and after successful execution, the digests @@ -17,64 +17,15 @@ class FileDigester(ForkProcess): __slots__ = ( "file_path", - "digests", "hash_names", - "_digest_pipe_reader", - "_digest_pw", ) def _start(self): - pr, pw = os.pipe() - self.fd_pipes = {} - self.fd_pipes[pw] = pw - self._digest_pw = pw - self._digest_pipe_reader = PipeReader( - input_files={"input": pr}, scheduler=self.scheduler + self.target = functools.partial( + perform_multiple_checksums, self.file_path, hashes=self.hash_names ) - self._digest_pipe_reader.addExitListener(self._digest_pipe_reader_exit) - self._digest_pipe_reader.start() - ForkProcess._start(self) - os.close(pw) - - def _run(self): - digests = perform_multiple_checksums(self.file_path, hashes=self.hash_names) - - buf = "".join("%s=%s\n" % item for item in digests.items()).encode("utf_8") - - while buf: - buf = buf[os.write(self._digest_pw, buf) :] - - return os.EX_OK - - def _parse_digests(self, data): - digests = {} - for line in data.decode("utf_8").splitlines(): - parts = line.split("=", 1) - if len(parts) == 2: - digests[parts[0]] = parts[1] - - self.digests = digests - - def _async_waitpid(self): - # Ignore this event, since we want to ensure that we - # exit only after _digest_pipe_reader has reached EOF. - if self._digest_pipe_reader is None: - ForkProcess._async_waitpid(self) - - def _digest_pipe_reader_exit(self, pipe_reader): - self._parse_digests(pipe_reader.getvalue()) - self._digest_pipe_reader = None - if self.pid is None: - self._unregister() - self._async_wait() - else: - self._async_waitpid() - - def _unregister(self): - ForkProcess._unregister(self) + super()._start() - pipe_reader = self._digest_pipe_reader - if pipe_reader is not None: - self._digest_pipe_reader = None - pipe_reader.removeExitListener(self._digest_pipe_reader_exit) - pipe_reader.cancel() + @property + def digests(self): + return self.result