1 |
Fix flaws in logic involving the updatecache_flg variable. Use this |
2 |
variable to skip hooks and metadata-transfer when sync fails (or the |
3 |
server timestamp has not changed). |
4 |
|
5 |
X-Gentoo-Bug: 564988 |
6 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=564988 |
7 |
--- |
8 |
pym/portage/emaint/modules/sync/sync.py | 15 ++++++++++----- |
9 |
pym/portage/sync/controller.py | 3 ++- |
10 |
pym/portage/sync/modules/rsync/rsync.py | 17 ++++++++++------- |
11 |
3 files changed, 22 insertions(+), 13 deletions(-) |
12 |
|
13 |
diff --git a/pym/portage/emaint/modules/sync/sync.py b/pym/portage/emaint/modules/sync/sync.py |
14 |
index 57c779d..faa20d9 100644 |
15 |
--- a/pym/portage/emaint/modules/sync/sync.py |
16 |
+++ b/pym/portage/emaint/modules/sync/sync.py |
17 |
@@ -232,16 +232,19 @@ class SyncRepos(object): |
18 |
sync_scheduler.wait() |
19 |
retvals = sync_scheduler.retvals |
20 |
msgs.extend(sync_scheduler.msgs) |
21 |
+ updatecache_flg = sync_scheduler.updatecache_flg |
22 |
|
23 |
- # run the post_sync_hook one last time for |
24 |
- # run only at sync completion hooks |
25 |
- rcode = sync_manager.perform_post_sync_hook('') |
26 |
if retvals: |
27 |
msgs.extend(self.rmessage(retvals, 'sync')) |
28 |
else: |
29 |
msgs.extend(self.rmessage([('None', os.EX_OK)], 'sync')) |
30 |
- if rcode: |
31 |
- msgs.extend(self.rmessage([('None', rcode)], 'post-sync')) |
32 |
+ |
33 |
+ if updatecache_flg: |
34 |
+ # run the post_sync_hook one last time for |
35 |
+ # run only at sync completion hooks |
36 |
+ rcode = sync_manager.perform_post_sync_hook('') |
37 |
+ if rcode: |
38 |
+ msgs.extend(self.rmessage([('None', rcode)], 'post-sync')) |
39 |
|
40 |
# Reload the whole config. |
41 |
portage._sync_mode = False |
42 |
@@ -321,6 +324,7 @@ class SyncScheduler(AsyncScheduler): |
43 |
self._init_graph() |
44 |
self.retvals = [] |
45 |
self.msgs = [] |
46 |
+ self.updatecache_flg = False |
47 |
|
48 |
def _init_graph(self): |
49 |
''' |
50 |
@@ -350,6 +354,7 @@ class SyncScheduler(AsyncScheduler): |
51 |
returncode = task.returncode |
52 |
if task.returncode == os.EX_OK: |
53 |
returncode, message, updatecache_flg = task.result |
54 |
+ self.updatecache_flg |= updatecache_flg |
55 |
if message: |
56 |
self.msgs.append(message) |
57 |
repo = task.kwargs['repo'].name |
58 |
diff --git a/pym/portage/sync/controller.py b/pym/portage/sync/controller.py |
59 |
index e8132c2..1beb545 100644 |
60 |
--- a/pym/portage/sync/controller.py |
61 |
+++ b/pym/portage/sync/controller.py |
62 |
@@ -156,7 +156,8 @@ class SyncManager(object): |
63 |
taskmaster = TaskHandler(callback=self.do_callback) |
64 |
taskmaster.run_tasks(tasks, func, status, options=task_opts) |
65 |
|
66 |
- self.perform_post_sync_hook(repo.name, repo.sync_uri, repo.location) |
67 |
+ if self.updatecache_flg: |
68 |
+ self.perform_post_sync_hook(repo.name, repo.sync_uri, repo.location) |
69 |
|
70 |
return self.exitcode, None, self.updatecache_flg |
71 |
|
72 |
diff --git a/pym/portage/sync/modules/rsync/rsync.py b/pym/portage/sync/modules/rsync/rsync.py |
73 |
index 8ae8a5c..e0f76b3 100644 |
74 |
--- a/pym/portage/sync/modules/rsync/rsync.py |
75 |
+++ b/pym/portage/sync/modules/rsync/rsync.py |
76 |
@@ -112,10 +112,10 @@ class RsyncSync(NewBase): |
77 |
if syncuri.startswith("file://"): |
78 |
self.proto = "file" |
79 |
dosyncuri = syncuri[6:] |
80 |
- is_synced, exitcode = self._do_rsync( |
81 |
+ is_synced, exitcode, updatecache_flg = self._do_rsync( |
82 |
dosyncuri, timestamp, opts) |
83 |
self._process_exitcode(exitcode, dosyncuri, out, 1) |
84 |
- return (exitcode, exitcode == os.EX_OK) |
85 |
+ return (exitcode, updatecache_flg) |
86 |
|
87 |
retries=0 |
88 |
try: |
89 |
@@ -138,7 +138,7 @@ class RsyncSync(NewBase): |
90 |
else: |
91 |
# getaddrinfo needs the brackets stripped |
92 |
getaddrinfo_host = hostname[1:-1] |
93 |
- updatecache_flg=True |
94 |
+ updatecache_flg = False |
95 |
all_rsync_opts = set(self.rsync_opts) |
96 |
all_rsync_opts.update(self.extra_rsync_opts) |
97 |
|
98 |
@@ -240,7 +240,8 @@ class RsyncSync(NewBase): |
99 |
if dosyncuri.startswith('ssh://'): |
100 |
dosyncuri = dosyncuri[6:].replace('/', ':/', 1) |
101 |
|
102 |
- is_synced, exitcode = self._do_rsync(dosyncuri, timestamp, opts) |
103 |
+ is_synced, exitcode, updatecache_flg = self._do_rsync( |
104 |
+ dosyncuri, timestamp, opts) |
105 |
if is_synced: |
106 |
break |
107 |
|
108 |
@@ -251,7 +252,6 @@ class RsyncSync(NewBase): |
109 |
else: |
110 |
# over retries |
111 |
# exit loop |
112 |
- updatecache_flg=False |
113 |
exitcode = EXCEEDED_MAX_RETRIES |
114 |
break |
115 |
self._process_exitcode(exitcode, dosyncuri, out, maxretries) |
116 |
@@ -382,6 +382,7 @@ class RsyncSync(NewBase): |
117 |
|
118 |
|
119 |
def _do_rsync(self, syncuri, timestamp, opts): |
120 |
+ updatecache_flg = False |
121 |
is_synced = False |
122 |
if timestamp != 0 and "--quiet" not in opts: |
123 |
print(">>> Checking server timestamp ...") |
124 |
@@ -489,7 +490,7 @@ class RsyncSync(NewBase): |
125 |
print(">>> In order to force sync, remove '%s'." % self.servertimestampfile) |
126 |
print(">>>") |
127 |
print() |
128 |
- return is_synced, exitcode |
129 |
+ return is_synced, exitcode, updatecache_flg |
130 |
elif (servertimestamp != 0) and (servertimestamp < timestamp): |
131 |
self.logger(self.xterm_titles, |
132 |
">>> Server out of date: %s" % syncuri) |
133 |
@@ -543,6 +544,8 @@ class RsyncSync(NewBase): |
134 |
os.unlink(self.servertimestampfile) |
135 |
except OSError: |
136 |
pass |
137 |
+ else: |
138 |
+ updatecache_flg = True |
139 |
|
140 |
if exitcode in [0,1,3,4,11,14,20,21]: |
141 |
is_synced = True |
142 |
@@ -554,4 +557,4 @@ class RsyncSync(NewBase): |
143 |
# --prune-empty-directories. Retry for a server that supports |
144 |
# at least rsync protocol version 29 (>=rsync-2.6.4). |
145 |
pass |
146 |
- return is_synced, exitcode |
147 |
+ return is_synced, exitcode, updatecache_flg |
148 |
-- |
149 |
2.4.9 |