commit:     8ddc902ba8cb4712a2a8b49f46951c8ec326a678
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Jan  3 02:48:32 2019 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Jan  3 06:21:42 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=8ddc902b

rsync: use ${PORTAGE_TMPDIR}/portage (bug 671808)

Write temporary timestamp files in ${PORTAGE_TMPDIR}/portage,
since writing files directly in ${PORTAGE_TMPDIR} is generally
unexpected. Also, use the rsync --inplace option, since it's
writing to a temp file created in advance and the usersync
user does not necessarily have write access to the parent
directory.

Bug: https://bugs.gentoo.org/671808
Bug: https://bugs.gentoo.org/336503
Fixes: 3f7f72cf339d ("Bug #336503 - Use PORTAGE_TMPDIR for the emerge --sync 
server timestamp")
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/sync/modules/rsync/rsync.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/portage/sync/modules/rsync/rsync.py 
b/lib/portage/sync/modules/rsync/rsync.py
index 0f8221776..e6f2688f8 100644
--- a/lib/portage/sync/modules/rsync/rsync.py
+++ b/lib/portage/sync/modules/rsync/rsync.py
@@ -583,11 +583,17 @@ class RsyncSync(NewBase):
                # Temporary file for remote server timestamp comparison.
                # NOTE: If FEATURES=usersync is enabled then the tempfile
                # needs to be in a directory that's readable by the usersync
-               # user. We assume that PORTAGE_TMPDIR will satisfy this
+               # user. We assume that ${PORTAGE_TMPDIR}/portage will satisfy 
this
                # requirement, since that's not necessarily true for the
                # default directory used by the tempfile module.
                if self.usersync_uid is not None:
-                       tmpdir = self.settings['PORTAGE_TMPDIR']
+                       tmpdir = os.path.join(self.settings['PORTAGE_TMPDIR'], 
'portage')
+                       ensure_dirs_kwargs = {}
+                       if portage.secpass >= 1:
+                               ensure_dirs_kwargs['gid'] = portage.portage_gid
+                               ensure_dirs_kwargs['mode'] = 0o70
+                               ensure_dirs_kwargs['mask'] = 0
+                       portage.util.ensure_dirs(tmpdir, **ensure_dirs_kwargs)
                else:
                        # use default dir from tempfile module
                        tmpdir = None
@@ -598,6 +604,7 @@ class RsyncSync(NewBase):
                        portage.util.apply_permissions(tmpservertimestampfile,
                                uid=self.usersync_uid)
                command = rsynccommand[:]
+               command.append('--inplace')
                command.append(syncuri.rstrip("/") + \
                        "/metadata/timestamp.chk")
                command.append(tmpservertimestampfile)

Reply via email to