From patchwork Mon Jul 18 16:11:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guilherme Salgado X-Patchwork-Id: 2741 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id A715224259 for ; Mon, 18 Jul 2011 16:11:09 +0000 (UTC) Received: from mail-qy0-f173.google.com (mail-qy0-f173.google.com [209.85.216.173]) by fiordland.canonical.com (Postfix) with ESMTP id 53C6AA18699 for ; Mon, 18 Jul 2011 16:11:09 +0000 (UTC) Received: by qyk10 with SMTP id 10so1936984qyk.11 for ; Mon, 18 Jul 2011 09:11:08 -0700 (PDT) Received: by 10.224.191.71 with SMTP id dl7mr5448053qab.12.1311005468713; Mon, 18 Jul 2011 09:11:08 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs59683qcb; Mon, 18 Jul 2011 09:11:08 -0700 (PDT) Received: by 10.216.235.207 with SMTP id u57mr5785824weq.42.1311005467291; Mon, 18 Jul 2011 09:11:07 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id k38si545609weq.28.2011.07.18.09.11.06; Mon, 18 Jul 2011 09:11:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QiqPS-0007Ox-FV for ; Mon, 18 Jul 2011 16:11:06 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 67EE82E896F for ; Mon, 18 Jul 2011 16:11:06 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-image-tools/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 377 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-image-tools/linaro-image-tools/trunk] Rev 377: Make sure rootfs.move_contents() doesn't skip files that are not world-readable. Message-Id: <20110718161106.4455.32241.launchpad@loganberry.canonical.com> Date: Mon, 18 Jul 2011 16:11:06 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13405"; Instance="initZopeless config overlay" X-Launchpad-Hash: b60f1de819220ec2e6a4b0d536046c9119403f00 Merge authors: Guilherme Salgado (salgado) Related merge proposals: https://code.launchpad.net/~salgado/linaro-image-tools/bug-789093/+merge/68266 proposed by: Guilherme Salgado (salgado) review: Approve - James Tunnicliffe (dooferlad) ------------------------------------------------------------ revno: 377 [merge] committer: Guilherme Salgado branch nick: trunk timestamp: Mon 2011-07-18 13:08:49 -0300 message: Make sure rootfs.move_contents() doesn't skip files that are not world-readable. modified: linaro_image_tools/media_create/rootfs.py linaro_image_tools/media_create/tests/test_media_create.py --- lp:linaro-image-tools https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk You are subscribed to branch lp:linaro-image-tools. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription === modified file 'linaro_image_tools/media_create/rootfs.py' --- linaro_image_tools/media_create/rootfs.py 2011-04-05 09:26:47 +0000 +++ linaro_image_tools/media_create/rootfs.py 2011-07-18 14:38:39 +0000 @@ -19,6 +19,7 @@ import glob import os +import subprocess import tempfile from linaro_image_tools import cmd_runner @@ -107,13 +108,26 @@ flash_kernel, "UBOOT_PART=%s" % target_boot_dev) +def _list_files(directory): + """List the files and dirs under the given directory. + + Runs as root because we want to list everything, including stuff that may + not be world-readable. + """ + p = cmd_runner.run( + ['find', directory, '-maxdepth', '1', '-mindepth', '1'], + stdout=subprocess.PIPE, as_root=True) + stdout, _ = p.communicate() + return stdout.split() + + def move_contents(from_, root_disk): """Move everything under from_ to the given root disk. Uses sudo for moving. """ assert os.path.isdir(from_), "%s is not a directory" % from_ - files = glob.glob(os.path.join(from_, '*')) + files = _list_files(from_) mv_cmd = ['mv'] mv_cmd.extend(sorted(files)) mv_cmd.append(root_disk) === modified file 'linaro_image_tools/media_create/tests/test_media_create.py' --- linaro_image_tools/media_create/tests/test_media_create.py 2011-07-05 15:00:22 +0000 +++ linaro_image_tools/media_create/tests/test_media_create.py 2011-07-18 14:38:39 +0000 @@ -2121,6 +2121,14 @@ os.makedirs(contents_bin) os.makedirs(contents_etc) + # Must mock rootfs._list_files() because populate_rootfs() uses its + # return value but since we mock cmd_runner.run() _list_files() would + # return an invalid value. + def mock_list_files(directory): + return [contents_bin, contents_etc] + self.useFixture(MockSomethingFixture( + rootfs, '_list_files', mock_list_files)) + populate_rootfs( contents_dir, root_disk, partition='/dev/rootfs', rootfs_type='ext3', rootfs_uuid='uuid', should_create_swap=True, @@ -2162,10 +2170,27 @@ fixture.mock.commands_executed[0]) self.assertEqual('UBOOT_PART=/dev/mmcblk0p1', open(tmpfile).read()) + def test_list_files(self): + tempdir = self.useFixture(CreateTempDirFixture()).tempdir + # We don't want to mock cmd_runner.run() because we're testing the + # command that it runs, but we need to monkey-patch SUDO_ARGS because + # we don't want to use 'sudo' in tests. + orig_sudo_args = cmd_runner.SUDO_ARGS + def restore_sudo_args(): + cmd_runner.SUDO_ARGS = orig_sudo_args + self.addCleanup(restore_sudo_args) + cmd_runner.SUDO_ARGS = [] + file1 = self.createTempFileAsFixture(dir=tempdir) + self.assertEqual([file1], rootfs._list_files(tempdir)) + def test_move_contents(self): tempdir = self.useFixture(CreateTempDirFixture()).tempdir popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) file1 = self.createTempFileAsFixture(dir=tempdir) + def mock_list_files(directory): + return [file1] + self.useFixture(MockSomethingFixture( + rootfs, '_list_files', mock_list_files)) move_contents(tempdir, '/tmp/')