diff options
Diffstat (limited to 'subcmds/sync.py')
| -rw-r--r-- | subcmds/sync.py | 68 |
1 files changed, 58 insertions, 10 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py index e75a8154..b848d137 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
| @@ -989,26 +989,16 @@ later is required to fix a server side protocol bug. | |||
| 989 | Returns: | 989 | Returns: |
| 990 | List of all projects that should be checked out. | 990 | List of all projects that should be checked out. |
| 991 | """ | 991 | """ |
| 992 | rp = manifest.repoProject | ||
| 993 | |||
| 994 | to_fetch = [] | 992 | to_fetch = [] |
| 995 | now = time.time() | ||
| 996 | if _ONE_DAY_S <= (now - rp.LastFetch): | ||
| 997 | to_fetch.append(rp) | ||
| 998 | to_fetch.extend(all_projects) | 993 | to_fetch.extend(all_projects) |
| 999 | to_fetch.sort(key=self._fetch_times.Get, reverse=True) | 994 | to_fetch.sort(key=self._fetch_times.Get, reverse=True) |
| 1000 | 995 | ||
| 1001 | result = self._Fetch(to_fetch, opt, err_event, ssh_proxy, errors) | 996 | result = self._Fetch(to_fetch, opt, err_event, ssh_proxy, errors) |
| 1002 | success = result.success | 997 | success = result.success |
| 1003 | fetched = result.projects | 998 | fetched = result.projects |
| 1004 | |||
| 1005 | if not success: | 999 | if not success: |
| 1006 | err_event.set() | 1000 | err_event.set() |
| 1007 | 1001 | ||
| 1008 | # Call self update, unless requested not to | ||
| 1009 | # TODO(b/42193561): Extract repo update logic to ExecuteHelper. | ||
| 1010 | if os.environ.get("REPO_SKIP_SELF_UPDATE", "0") == "0": | ||
| 1011 | _PostRepoFetch(rp, opt.repo_verify) | ||
| 1012 | if opt.network_only: | 1002 | if opt.network_only: |
| 1013 | # Bail out now; the rest touches the working tree. | 1003 | # Bail out now; the rest touches the working tree. |
| 1014 | if err_event.is_set(): | 1004 | if err_event.is_set(): |
| @@ -1369,6 +1359,61 @@ later is required to fix a server side protocol bug. | |||
| 1369 | t.join() | 1359 | t.join() |
| 1370 | pm.end() | 1360 | pm.end() |
| 1371 | 1361 | ||
| 1362 | def _UpdateRepoProject(self, opt, manifest, errors): | ||
| 1363 | """Fetch the repo project and check for updates.""" | ||
| 1364 | if opt.local_only: | ||
| 1365 | return | ||
| 1366 | |||
| 1367 | rp = manifest.repoProject | ||
| 1368 | now = time.time() | ||
| 1369 | # If we've fetched in the last day, don't bother fetching again. | ||
| 1370 | if (now - rp.LastFetch) < _ONE_DAY_S: | ||
| 1371 | return | ||
| 1372 | |||
| 1373 | with multiprocessing.Manager() as manager: | ||
| 1374 | with ssh.ProxyManager(manager) as ssh_proxy: | ||
| 1375 | ssh_proxy.sock() | ||
| 1376 | start = time.time() | ||
| 1377 | buf = TeeStringIO(sys.stdout if opt.verbose else None) | ||
| 1378 | sync_result = rp.Sync_NetworkHalf( | ||
| 1379 | quiet=opt.quiet, | ||
| 1380 | verbose=opt.verbose, | ||
| 1381 | output_redir=buf, | ||
| 1382 | current_branch_only=self._GetCurrentBranchOnly( | ||
| 1383 | opt, manifest | ||
| 1384 | ), | ||
| 1385 | force_sync=opt.force_sync, | ||
| 1386 | clone_bundle=opt.clone_bundle, | ||
| 1387 | tags=opt.tags, | ||
| 1388 | archive=manifest.IsArchive, | ||
| 1389 | optimized_fetch=opt.optimized_fetch, | ||
| 1390 | retry_fetches=opt.retry_fetches, | ||
| 1391 | prune=opt.prune, | ||
| 1392 | ssh_proxy=ssh_proxy, | ||
| 1393 | clone_filter=manifest.CloneFilter, | ||
| 1394 | partial_clone_exclude=manifest.PartialCloneExclude, | ||
| 1395 | clone_filter_for_depth=manifest.CloneFilterForDepth, | ||
| 1396 | ) | ||
| 1397 | if sync_result.error: | ||
| 1398 | errors.append(sync_result.error) | ||
| 1399 | |||
| 1400 | finish = time.time() | ||
| 1401 | self.event_log.AddSync( | ||
| 1402 | rp, | ||
| 1403 | event_log.TASK_SYNC_NETWORK, | ||
| 1404 | start, | ||
| 1405 | finish, | ||
| 1406 | sync_result.success, | ||
| 1407 | ) | ||
| 1408 | if not sync_result.success: | ||
| 1409 | logger.error("error: Cannot fetch repo tool %s", rp.name) | ||
| 1410 | return | ||
| 1411 | |||
| 1412 | # After fetching, check if a new version of repo is available and | ||
| 1413 | # restart. This is only done if the user hasn't explicitly disabled it. | ||
| 1414 | if os.environ.get("REPO_SKIP_SELF_UPDATE", "0") == "0": | ||
| 1415 | _PostRepoFetch(rp, opt.repo_verify) | ||
| 1416 | |||
| 1372 | def _ReloadManifest(self, manifest_name, manifest): | 1417 | def _ReloadManifest(self, manifest_name, manifest): |
| 1373 | """Reload the manfiest from the file specified by the |manifest_name|. | 1418 | """Reload the manfiest from the file specified by the |manifest_name|. |
| 1374 | 1419 | ||
| @@ -1871,6 +1916,9 @@ later is required to fix a server side protocol bug. | |||
| 1871 | # might be in the manifest. | 1916 | # might be in the manifest. |
| 1872 | self._ValidateOptionsWithManifest(opt, mp) | 1917 | self._ValidateOptionsWithManifest(opt, mp) |
| 1873 | 1918 | ||
| 1919 | # Update the repo project and check for new versions of repo. | ||
| 1920 | self._UpdateRepoProject(opt, manifest, errors) | ||
| 1921 | |||
| 1874 | superproject_logging_data = {} | 1922 | superproject_logging_data = {} |
| 1875 | self._UpdateProjectsRevisionId( | 1923 | self._UpdateProjectsRevisionId( |
| 1876 | opt, args, superproject_logging_data, manifest | 1924 | opt, args, superproject_logging_data, manifest |
