def MoveFiles(rebalance, is_master):
  """Commit the received files into the database."""
  loc = data_store.DB.Location()
  if not os.path.exists(loc):
    return False
  if not os.path.isdir(loc):
    return False
  tempdir = _CreateDirectory(loc, rebalance.id)
  # Read files to remove.
  remove_file = _FileWithRemoveList(loc, rebalance)
  to_remove = []
  if os.path.exists(remove_file):
    to_remove = [line.decode("utf8").rstrip("\n")
                 for line in open(remove_file, "r")]
  for fname in to_remove:
    if not fname.startswith(loc):
      logging.warning("Wrong file to remove: %s", fname)
      continue
    if not os.path.exists(fname):
      logging.warning("File does not exist: %s", fname)
      continue
    if not os.path.isfile(fname):
      logging.warning("Not a file: %s", fname)
      continue
    os.unlink(fname)
    logging.info("Removing file %s", fname)
  try:
    os.unlink(remove_file)
  except __HOLE__:
    pass
  # Move files.
  try:
    _RecMoveFiles(tempdir, loc, "")
  except OSError:
    return False
  # Remove temporary directory.
  # Master will remove it later.
  if not is_master:
    if tempdir.startswith(loc):
      shutil.rmtree(tempdir)
  return True
dataset/ETHPy150Open google/grr/grr/server/data_server/rebalance.py/MoveFiles