From 6f46c24213894ee3753687edabc3058d8880db98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B8=D1=80=D0=B5=D1=86=D0=BA=D0=B8=D0=B9=20=D0=9C?= =?UTF-8?q?=D0=B8=D1=85=D0=B0=D0=B8=D0=BB?= Date: Thu, 21 Dec 2017 17:03:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B0=20=D0=BD=D0=B0=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BA=D1=80=D1=8B=D1=82=D1=8B=D0=B5=20=D1=80=D0=B5=D0=BF?= =?UTF-8?q?=D0=BE=D0=B7=D0=B8=D1=82=D0=BE=D1=80=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit От чтения закрываются .git, profiles/templates все ini.env и calculate.env. Доступ к профилям нужен, иначе при запуске emerge от пользователя будут сообщения о том, что невозможно определить профиль --- pym/update/profile.py | 7 +++++++ pym/update/update.py | 46 ++++++++++++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/pym/update/profile.py b/pym/update/profile.py index 7a5c05e..11017eb 100644 --- a/pym/update/profile.py +++ b/pym/update/profile.py @@ -15,6 +15,7 @@ # limitations under the License. import sys +import os from os import path import shutil from calculate.lib.utils.files import (listDirectory, readFile, readLinesFile, @@ -205,6 +206,12 @@ class ProfileRepository(object): rpath = path.join(storage.directory, name) if path.exists(rpath): removeDir(rpath) + if git.is_private_url(url): + try: + makeDirectory(rpath) + os.chmod(rpath, 0700) + except OSError: + pass git.cloneRepository(url, rpath, branch) pr = cls(git, name, storage) repo_name = pr.repo_name diff --git a/pym/update/update.py b/pym/update/update.py index 55db480..e5f8643 100644 --- a/pym/update/update.py +++ b/pym/update/update.py @@ -37,6 +37,7 @@ from calculate.lib.cl_log import log import re import shutil from collections import MutableSet +from contextlib import contextmanager from calculate.lib.utils.git import Git, GitError, MTimeKeeper, NotGitError from calculate.lib.utils.portage import (Layman, EmergeLog, @@ -51,7 +52,8 @@ Colors = TextState.Colors from calculate.lib.utils.files import (getProgPath, STDOUT, removeDir, PercentProgress, process, getRunCommands, readFile, listDirectory, pathJoin, - writeFile) + find, FindFileType, + writeFile, makeDirectory) import emerge_parser import logging from emerge_parser import (EmergeParser, EmergeCommand, EmergeError, @@ -156,6 +158,30 @@ class Update(MethodsInterface): def getGit(self): return self.clVars.Get('cl_update_git') + @contextmanager + def private_repo(self, rpath, url): + if Git.is_private_url(url): + try: + if not path.exists(rpath): + makeDirectory(rpath) + os.chmod(rpath, 0700) + yield + finally: + try: + for dn in (Git._gitDir(rpath), path.join(rpath, "profiles/templates")): + if path.exists(dn): + os.chmod(dn, 0700) + for fn in find(path.join(rpath, "profiles"), True, FindFileType.RegularFile, + True, None, downfilter=lambda x: not x.endswith("/templates")): + if fn.endswith("calculate.env") or fn.endswith("ini.env"): + os.chmod(fn, 0600) + if path.exists(rpath): + os.chmod(rpath, 0755) + except OSError: + pass + else: + yield + def _syncRepository(self, name, url, rpath, revision, cb_progress=None, clean=False, notask=False): """ @@ -174,8 +200,9 @@ class Update(MethodsInterface): self.startTask(_("Syncing the {rep} repository").format( rep=name.capitalize())) self.addProgress() - git.cloneTagRepository(url, rpath, revision, - cb_progress=cb_progress) + with self.private_repo(rpath, url): + git.cloneTagRepository(url, rpath, revision, + cb_progress=cb_progress) info_outdated = True else: cr = "" @@ -197,9 +224,10 @@ class Update(MethodsInterface): self.startTask(_("Syncing the {rep} repository").format( rep=name.capitalize())) self.addProgress() - git.updateTagRepository(url, rpath, revision, - cb_progress=cb_progress, - clean=clean) + with self.private_repo(rpath, url): + git.updateTagRepository(url, rpath, revision, + cb_progress=cb_progress, + clean=clean) new_cr = git.getCurrentCommit(rpath) if new_cr != cr: info_outdated = True @@ -385,12 +413,6 @@ class Update(MethodsInterface): if repname not in ("portage", "gentoo"): layman.add(repname, url, rpath_orig) finally: - try: - if (path.exists(rpath) and - Git.parse_url(url)[0] == Git.GitProtocol.SSH): - os.chmod(rpath, 0700) - except OSError: - pass mtime.restore() return True