From b92eed0b40b9a6f5c0b142af9de5b9b5c87faac1 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Tue, 20 Feb 2018 16:47:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20mode=20=D0=B8=20owner=20=D1=83=20=D1=84?= =?UTF-8?q?=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20=D0=BF=D1=80=D0=B8=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B8=20.=5Fcfg0000?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/calculate/lib/cl_template.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pym/calculate/lib/cl_template.py b/pym/calculate/lib/cl_template.py index 70c5c74..bf6a9f3 100644 --- a/pym/calculate/lib/cl_template.py +++ b/pym/calculate/lib/cl_template.py @@ -1596,6 +1596,7 @@ class _file(_error): self.nameFileConfig = os.path.abspath(nameFileConfig) self.nameFileTemplate = os.path.abspath(nameFileTemplate) self.F_TEMPL = self.openTemplFile(self.nameFileTemplate) + copy_stat = not os.path.exists(self.nameFileConfig) if (not self.executeType and typeFormat not in HParams.Formats.Executable): self.F_CONF = self.__openConfFile(self.nameFileConfig) @@ -1606,11 +1607,25 @@ class _file(_error): self.nameFileConfig) if newBuffer is None: self.textConfig = readFile(origConfigName) + if copy_stat: + self.copy_mod_own(origConfigName, self.nameFileConfig) else: self.textConfig = newBuffer else: self.textConfig = self.F_CONF.read() + def copy_mod_own(self, source, target): + try: + statdata = os.stat(source) + statdata_old = os.stat(target) + if statdata.st_mode != statdata_old.st_mode: + os.chmod(target, statdata.st_mode) + if (statdata.st_uid != statdata_old.st_uid or + statdata.st_gid != statdata_old.st_gid): + os.chown(target, statdata.st_uid, statdata.st_gid) + except OSError: + pass + def __del__(self): self.closeFiles() @@ -4578,6 +4593,7 @@ gettext -d cl_template "$*" try: open(filename, 'w').write( readFile(cfgs[filename][0][1])) + self.copy_mod_own(cfgs[filename][0][1], filename) except Exception as e: self.printERROR(str(e)) self.printWARNING(