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 8793B138AE9 for ; Fri, 29 Dec 2017 20:40:02 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 058B9E0BF4; Fri, 29 Dec 2017 20:40:00 +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 C7DACE0824 for ; Fri, 29 Dec 2017 20:39:59 +0000 (UTC) Received: from localhost.localdomain (ip68-4-233-67.oc.oc.cox.net [68.4.233.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: zmedico) by smtp.gentoo.org (Postfix) with ESMTPSA id 89CEA340806; Fri, 29 Dec 2017 20:39:56 +0000 (UTC) From: Zac Medico To: gentoo-portage-dev@lists.gentoo.org Cc: Zac Medico Subject: [gentoo-portage-dev] [PATCH] bin/doins.py: implement install -p option (bug 642632) Date: Fri, 29 Dec 2017 12:35:31 -0800 Message-Id: <20171229203531.138617-1-zmedico@gentoo.org> X-Mailer: git-send-email 2.13.6 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-Archives-Salt: 18b51359-6c11-4059-b47f-588b7c39117e X-Archives-Hash: e4857ce149479c2660f267663bc80ef9 Bug: https://bugs.gentoo.org/642632 --- bin/doins.py | 13 ++++++++++--- pym/portage/tests/bin/test_doins.py | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/doins.py b/bin/doins.py index 92e450979..dceffee83 100644 --- a/bin/doins.py +++ b/bin/doins.py @@ -107,6 +107,7 @@ def _parse_install_options( parser.add_argument('-g', '--group', default=-1, type=_parse_group) parser.add_argument('-o', '--owner', default=-1, type=_parse_user) parser.add_argument('-m', '--mode', default=0o755, type=_parse_mode) + parser.add_argument('-p', '--preserve-timestamps', action='store_true') split_options = shlex.split(options) namespace, remaining = parser.parse_known_args(split_options) # Because parsing '--mode' option is partially supported. If unknown @@ -168,7 +169,8 @@ class _InsInProcessInstallRunner(object): True on success, otherwise False. """ dest = os.path.join(dest_dir, os.path.basename(source)) - if not self._is_install_allowed(source, dest): + sstat = os.stat(source) + if not self._is_install_allowed(source, sstat, dest): return False # To emulate the `install` command, remove the dest file in @@ -187,6 +189,11 @@ class _InsInProcessInstallRunner(object): movefile._copyxattr( source, dest, exclude=self._xattr_exclude) + if self._parsed_options.preserve_timestamps: + if sys.version_info >= (3, 3): + os.utime(dest, ns=(sstat.st_mtime_ns, sstat.st_mtime_ns)) + else: + os.utime(dest, (sstat.st_mtime, sstat.st_mtime)) except Exception: logging.exception( 'Failed to copy file: ' @@ -195,13 +202,14 @@ class _InsInProcessInstallRunner(object): return False return True - def _is_install_allowed(self, source, dest): + def _is_install_allowed(self, source, source_stat, dest): """Returns if installing source into dest should work. This is to keep compatibility with the `install` command. Args: source: path to the source file. + source_stat: stat result for the source file. dest: path to the dest file. Returns: @@ -210,7 +218,6 @@ class _InsInProcessInstallRunner(object): # To match `install` command, use stat() for source, while # lstat() for dest. Raise an exception if stat(source) fails, # intentionally. - source_stat = os.stat(source) try: dest_lstat = os.lstat(dest) except OSError as e: diff --git a/pym/portage/tests/bin/test_doins.py b/pym/portage/tests/bin/test_doins.py index 14d7adfa6..dd40abf6e 100644 --- a/pym/portage/tests/bin/test_doins.py +++ b/pym/portage/tests/bin/test_doins.py @@ -38,7 +38,7 @@ class DoIns(setup_env.BinTestCase): self.init() try: env = setup_env.env - env['INSOPTIONS'] = '-m0644' + env['INSOPTIONS'] = '-pm0644' with open(os.path.join(env['S'], 'test'), 'w'): pass doins('test') @@ -145,7 +145,7 @@ class DoIns(setup_env.BinTestCase): env = setup_env.env # Use an option which doins.py does not know. # Then, fallback to `install` command is expected. - env['INSOPTIONS'] = '-p' + env['INSOPTIONS'] = '-b' with open(os.path.join(env['S'], 'test'), 'w'): pass doins('test') -- 2.13.6