def test_dest_block_symlink(self): """Do not allow writing to a symlink.""" src = os.path.join(self.worktree, 'foo.txt') self.touch(src) platform_utils.symlink('dest', os.path.join(self.topdir, 'sym')) cf = self.CopyFile('foo.txt', 'sym') self.assertRaises(error.ManifestInvalidPathError, cf._Copy)
def test_dest_block_symlink_traversal(self): """Do not allow writing through a symlink dir.""" src = os.path.join(self.worktree, 'foo.txt') self.touch(src) platform_utils.symlink(tempfile.gettempdir(), os.path.join(self.topdir, 'sym')) cf = self.CopyFile('foo.txt', 'sym/foo.txt') self.assertRaises(error.ManifestInvalidPathError, cf._Copy)
def test_src_block_symlink(self): """Do not allow reading from a symlinked path.""" src = os.path.join(self.worktree, 'foo.txt') sym = os.path.join(self.worktree, 'sym') self.touch(src) platform_utils.symlink('foo.txt', sym) self.assertExists(sym) cf = self.CopyFile('sym', 'foo') self.assertRaises(error.ManifestInvalidPathError, cf._Copy)
def test_src_block_symlink_traversal(self): """Do not allow reading through a symlink dir.""" realfile = os.path.join(self.tempdir, 'file.txt') self.touch(realfile) src = os.path.join(self.worktree, 'bar', 'file.txt') platform_utils.symlink(self.tempdir, os.path.join(self.worktree, 'bar')) self.assertExists(src) cf = self.CopyFile('bar/file.txt', 'foo') self.assertRaises(error.ManifestInvalidPathError, cf._Copy)
def Link(self, name): """Update the repo metadata to use a different manifest. """ self.Override(name) try: if os.path.lexists(self.manifestFile): platform_utils.remove(self.manifestFile) platform_utils.symlink(os.path.join('manifests', name), self.manifestFile) except OSError as e: raise ManifestParseError('cannot link manifest %s: %s' % (name, str(e)))
def test_update(self): """Make sure changed targets get updated.""" dest = os.path.join(self.topdir, 'sym') src = os.path.join(self.worktree, 'foo.txt') self.touch(src) lf = self.LinkFile('foo.txt', 'sym') lf._Link() self.assertEqual(os.path.join('git-project', 'foo.txt'), os.readlink(dest)) # Point the symlink somewhere else. os.unlink(dest) platform_utils.symlink(self.tempdir, dest) lf._Link() self.assertEqual(os.path.join('git-project', 'foo.txt'), os.readlink(dest))
def _PostRepoUpgrade(manifest, quiet=False): # Link the docs for the internal .repo/ layout for people link = os.path.join(manifest.repodir, 'internal-fs-layout.md') if not platform_utils.islink(link): target = os.path.join('repo', 'docs', 'internal-fs-layout.md') try: platform_utils.symlink(target, link) except Exception: pass wrapper = Wrapper() if wrapper.NeedSetupGnuPG(): wrapper.SetupGnuPG(quiet) for project in manifest.projects: if project.Exists: project.PostRepoUpgrade()