Ejemplo n.º 1
0
  def _DeleteProject(self, path):
    print('Deleting obsolete path %s' % path, file=sys.stderr)

    # Delete the .git directory first, so we're less likely to have a partially
    # working git repository around. There shouldn't be any git projects here,
    # so rmtree works.
    try:
      platform_utils.rmtree(os.path.join(path, '.git'))
    except OSError as e:
      print('Failed to remove %s (%s)' % (os.path.join(path, '.git'), str(e)), file=sys.stderr)
      print('error: Failed to delete obsolete path %s' % path, file=sys.stderr)
      print('       remove manually, then run sync again', file=sys.stderr)
      return 1

    # Delete everything under the worktree, except for directories that contain
    # another git project
    dirs_to_remove = []
    failed = False
    for root, dirs, files in platform_utils.walk(path):
      for f in files:
        try:
          platform_utils.remove(os.path.join(root, f))
        except OSError as e:
          print('Failed to remove %s (%s)' % (os.path.join(root, f), str(e)), file=sys.stderr)
          failed = True
      dirs[:] = [d for d in dirs
                 if not os.path.lexists(os.path.join(root, d, '.git'))]
      dirs_to_remove += [os.path.join(root, d) for d in dirs
                         if os.path.join(root, d) not in dirs_to_remove]
    for d in reversed(dirs_to_remove):
      if platform_utils.islink(d):
        try:
          platform_utils.remove(d)
        except OSError as e:
          print('Failed to remove %s (%s)' % (os.path.join(root, d), str(e)), file=sys.stderr)
          failed = True
      elif len(platform_utils.listdir(d)) == 0:
        try:
          platform_utils.rmdir(d)
        except OSError as e:
          print('Failed to remove %s (%s)' % (os.path.join(root, d), str(e)), file=sys.stderr)
          failed = True
          continue
    if failed:
      print('error: Failed to delete obsolete path %s' % path, file=sys.stderr)
      print('       remove manually, then run sync again', file=sys.stderr)
      return 1

    # Try deleting parent dirs if they are empty
    project_dir = path
    while project_dir != self.manifest.topdir:
      if len(platform_utils.listdir(project_dir)) == 0:
        platform_utils.rmdir(project_dir)
      else:
        break
      project_dir = os.path.dirname(project_dir)

    return 0
Ejemplo n.º 2
0
  def _DeleteProject(self, path):
    print('Deleting obsolete path %s' % path, file=sys.stderr)

    # Delete the .git directory first, so we're less likely to have a partially
    # working git repository around. There shouldn't be any git projects here,
    # so rmtree works.
    try:
      platform_utils.rmtree(os.path.join(path, '.git'))
    except OSError as e:
      print('Failed to remove %s (%s)' % (os.path.join(path, '.git'), str(e)), file=sys.stderr)
      print('error: Failed to delete obsolete path %s' % path, file=sys.stderr)
      print('       remove manually, then run sync again', file=sys.stderr)
      return -1

    # Delete everything under the worktree, except for directories that contain
    # another git project
    dirs_to_remove = []
    failed = False
    for root, dirs, files in platform_utils.walk(path):
      for f in files:
        try:
          platform_utils.remove(os.path.join(root, f))
        except OSError as e:
          print('Failed to remove %s (%s)' % (os.path.join(root, f), str(e)), file=sys.stderr)
          failed = True
      dirs[:] = [d for d in dirs
                 if not os.path.lexists(os.path.join(root, d, '.git'))]
      dirs_to_remove += [os.path.join(root, d) for d in dirs
                         if os.path.join(root, d) not in dirs_to_remove]
    for d in reversed(dirs_to_remove):
      if platform_utils.islink(d):
        try:
          platform_utils.remove(d)
        except OSError as e:
          print('Failed to remove %s (%s)' % (os.path.join(root, d), str(e)), file=sys.stderr)
          failed = True
      elif len(platform_utils.listdir(d)) == 0:
        try:
          platform_utils.rmdir(d)
        except OSError as e:
          print('Failed to remove %s (%s)' % (os.path.join(root, d), str(e)), file=sys.stderr)
          failed = True
          continue
    if failed:
      print('error: Failed to delete obsolete path %s' % path, file=sys.stderr)
      print('       remove manually, then run sync again', file=sys.stderr)
      return -1

    # Try deleting parent dirs if they are empty
    project_dir = path
    while project_dir != self.manifest.topdir:
      if len(platform_utils.listdir(project_dir)) == 0:
        platform_utils.rmdir(project_dir)
      else:
        break
      project_dir = os.path.dirname(project_dir)

    return 0
Ejemplo n.º 3
0
    def close(self):
        """Close this active ssh session.

    Kill all ssh clients & masters we created, and nuke the socket dir.
    """
        self._terminate(self._clients)
        self._terminate(self._masters)

        d = self.sock(create=False)
        if d:
            try:
                platform_utils.rmdir(os.path.dirname(d))
            except OSError:
                pass
Ejemplo n.º 4
0
def close_ssh():
    global _master_keys_lock

    terminate_ssh_clients()

    for p in _master_processes:
        try:
            os.kill(p.pid, SIGTERM)
            p.wait()
        except OSError:
            pass
    del _master_processes[:]
    _master_keys.clear()

    d = ssh_sock(create=False)
    if d:
        try:
            platform_utils.rmdir(os.path.dirname(d))
        except OSError:
            pass

    # We're done with the lock, so we can delete it.
    _master_keys_lock = None
Ejemplo n.º 5
0
def close_ssh():
  global _master_keys_lock

  terminate_ssh_clients()

  for p in _master_processes:
    try:
      os.kill(p.pid, SIGTERM)
      p.wait()
    except OSError:
      pass
  del _master_processes[:]
  _master_keys.clear()

  d = ssh_sock(create=False)
  if d:
    try:
      platform_utils.rmdir(os.path.dirname(d))
    except OSError:
      pass

  # We're done with the lock, so we can delete it.
  _master_keys_lock = None