Copy the binaries from the temporary unpack location.

    We need to first stop the running service or we might not be able to write
    on the binary. We then copy the entire directory where we are running from
    into the location indicated by "Client.install_path".

def RunOnce(self):
    """Copy the binaries from the temporary unpack location.

    We need to first stop the running service or we might not be able to write
    on the binary. We then copy the entire directory where we are running from
    into the location indicated by "Client.install_path".
    """
    self.StopPreviousService()

    executable_directory = os.path.dirname(sys.executable)
    install_path = config.CONFIG["Client.install_path"]
    logging.info("Installing binaries %s -> %s", executable_directory,
                 config.CONFIG["Client.install_path"])
    if os.path.exists(install_path):
      attempts = 0
      while True:
        try:
          shutil.rmtree(install_path)
          break
        except OSError as e:
          attempts += 1
          if e.errno == errno.EACCES and attempts < 10:
            # The currently installed GRR process may stick around for a few
            # seconds after the service is terminated (keeping the contents of
            # the installation directory locked).
            logging.warning(
                "Encountered permission-denied error while trying to empty out "
                "'%s'. Retrying...", install_path)
            time.sleep(3)
          else:
            raise e
    os.makedirs(install_path)

    # Recursively copy the temp directory to the installation directory.
    for root, dirs, files in os.walk(executable_directory):
      for name in dirs:
        src_path = os.path.join(root, name)
        relative_path = os.path.relpath(src_path, executable_directory)
        dest_path = os.path.join(install_path, relative_path)

        try:
          os.mkdir(dest_path)
        except OSError as e:
          # Ignore already-exists exceptions.
          if e.errno != errno.EEXIST:
            raise

      for name in files:
        src_path = os.path.join(root, name)
        relative_path = os.path.relpath(src_path, executable_directory)
        dest_path = os.path.join(install_path, relative_path)

        shutil.copy(src_path, dest_path)