Изменены права на закрытые репозитории

От чтения закрываются .git, profiles/templates все ini.env и
calculate.env. Доступ к профилям нужен, иначе при запуске emerge от
пользователя будут сообщения о том, что невозможно определить профиль
master-3.5 3.5.8.1
parent 321f616059
commit 6f46c24213

@ -15,6 +15,7 @@
# limitations under the License. # limitations under the License.
import sys import sys
import os
from os import path from os import path
import shutil import shutil
from calculate.lib.utils.files import (listDirectory, readFile, readLinesFile, from calculate.lib.utils.files import (listDirectory, readFile, readLinesFile,
@ -205,6 +206,12 @@ class ProfileRepository(object):
rpath = path.join(storage.directory, name) rpath = path.join(storage.directory, name)
if path.exists(rpath): if path.exists(rpath):
removeDir(rpath) removeDir(rpath)
if git.is_private_url(url):
try:
makeDirectory(rpath)
os.chmod(rpath, 0700)
except OSError:
pass
git.cloneRepository(url, rpath, branch) git.cloneRepository(url, rpath, branch)
pr = cls(git, name, storage) pr = cls(git, name, storage)
repo_name = pr.repo_name repo_name = pr.repo_name

@ -37,6 +37,7 @@ from calculate.lib.cl_log import log
import re import re
import shutil import shutil
from collections import MutableSet from collections import MutableSet
from contextlib import contextmanager
from calculate.lib.utils.git import Git, GitError, MTimeKeeper, NotGitError from calculate.lib.utils.git import Git, GitError, MTimeKeeper, NotGitError
from calculate.lib.utils.portage import (Layman, EmergeLog, from calculate.lib.utils.portage import (Layman, EmergeLog,
@ -51,7 +52,8 @@ Colors = TextState.Colors
from calculate.lib.utils.files import (getProgPath, STDOUT, removeDir, from calculate.lib.utils.files import (getProgPath, STDOUT, removeDir,
PercentProgress, process, getRunCommands, PercentProgress, process, getRunCommands,
readFile, listDirectory, pathJoin, readFile, listDirectory, pathJoin,
writeFile) find, FindFileType,
writeFile, makeDirectory)
import emerge_parser import emerge_parser
import logging import logging
from emerge_parser import (EmergeParser, EmergeCommand, EmergeError, from emerge_parser import (EmergeParser, EmergeCommand, EmergeError,
@ -156,6 +158,30 @@ class Update(MethodsInterface):
def getGit(self): def getGit(self):
return self.clVars.Get('cl_update_git') 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, def _syncRepository(self, name, url, rpath, revision,
cb_progress=None, clean=False, notask=False): cb_progress=None, clean=False, notask=False):
""" """
@ -174,8 +200,9 @@ class Update(MethodsInterface):
self.startTask(_("Syncing the {rep} repository").format( self.startTask(_("Syncing the {rep} repository").format(
rep=name.capitalize())) rep=name.capitalize()))
self.addProgress() self.addProgress()
git.cloneTagRepository(url, rpath, revision, with self.private_repo(rpath, url):
cb_progress=cb_progress) git.cloneTagRepository(url, rpath, revision,
cb_progress=cb_progress)
info_outdated = True info_outdated = True
else: else:
cr = "" cr = ""
@ -197,9 +224,10 @@ class Update(MethodsInterface):
self.startTask(_("Syncing the {rep} repository").format( self.startTask(_("Syncing the {rep} repository").format(
rep=name.capitalize())) rep=name.capitalize()))
self.addProgress() self.addProgress()
git.updateTagRepository(url, rpath, revision, with self.private_repo(rpath, url):
cb_progress=cb_progress, git.updateTagRepository(url, rpath, revision,
clean=clean) cb_progress=cb_progress,
clean=clean)
new_cr = git.getCurrentCommit(rpath) new_cr = git.getCurrentCommit(rpath)
if new_cr != cr: if new_cr != cr:
info_outdated = True info_outdated = True
@ -385,12 +413,6 @@ class Update(MethodsInterface):
if repname not in ("portage", "gentoo"): if repname not in ("portage", "gentoo"):
layman.add(repname, url, rpath_orig) layman.add(repname, url, rpath_orig)
finally: finally:
try:
if (path.exists(rpath) and
Git.parse_url(url)[0] == Git.GitProtocol.SSH):
os.chmod(rpath, 0700)
except OSError:
pass
mtime.restore() mtime.restore()
return True return True

Loading…
Cancel
Save