Blame tests/test-rollsum-cli.c

Packit Service 2a3f3d
/*
Packit Service 2a3f3d
 * Copyright (C) 2013 Colin Walters <walters@verbum.org>
Packit Service 2a3f3d
 *
Packit Service 2a3f3d
 * SPDX-License-Identifier: LGPL-2.0+
Packit Service 2a3f3d
 *
Packit Service 2a3f3d
 * This library is free software; you can redistribute it and/or
Packit Service 2a3f3d
 * modify it under the terms of the GNU Lesser General Public
Packit Service 2a3f3d
 * License as published by the Free Software Foundation; either
Packit Service 2a3f3d
 * version 2 of the License, or (at your option) any later version.
Packit Service 2a3f3d
 *
Packit Service 2a3f3d
 * This library is distributed in the hope that it will be useful,
Packit Service 2a3f3d
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 2a3f3d
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 2a3f3d
 * Lesser General Public License for more details.
Packit Service 2a3f3d
 *
Packit Service 2a3f3d
 * You should have received a copy of the GNU Lesser General Public
Packit Service 2a3f3d
 * License along with this library; if not, write to the
Packit Service 2a3f3d
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit Service 2a3f3d
 * Boston, MA 02111-1307, USA.
Packit Service 2a3f3d
 */
Packit Service 2a3f3d
Packit Service 2a3f3d
#include "config.h"
Packit Service 2a3f3d
Packit Service 2a3f3d
#include "ostree-rollsum.h"
Packit Service 2a3f3d
Packit Service 2a3f3d
#include "libglnx.h"
Packit Service 2a3f3d
Packit Service 2a3f3d
int
Packit Service 2a3f3d
main (int argc, char **argv)
Packit Service 2a3f3d
{
Packit Service 2a3f3d
  g_autoptr(GError) local_error = NULL;
Packit Service 2a3f3d
  GError **error = &local_error;
Packit Service 2a3f3d
  GBytes *from_bytes = NULL;
Packit Service 2a3f3d
  GBytes *to_bytes = NULL;
Packit Service 2a3f3d
  const char *from_path;
Packit Service 2a3f3d
  const char *to_path;
Packit Service 2a3f3d
  OstreeRollsumMatches *matches;
Packit Service 2a3f3d
  GMappedFile *mfile;
Packit Service 2a3f3d
Packit Service 2a3f3d
  g_setenv ("GIO_USE_VFS", "local", TRUE);
Packit Service 2a3f3d
Packit Service 2a3f3d
  if (argc < 3)
Packit Service 2a3f3d
    return 1;
Packit Service 2a3f3d
Packit Service 2a3f3d
  from_path = argv[1];
Packit Service 2a3f3d
  to_path = argv[2];
Packit Service 2a3f3d
Packit Service 2a3f3d
  mfile = g_mapped_file_new (from_path, FALSE, error);
Packit Service 2a3f3d
  if (!mfile)
Packit Service 2a3f3d
    goto out;
Packit Service 2a3f3d
  from_bytes = g_mapped_file_get_bytes (mfile);
Packit Service 2a3f3d
  g_mapped_file_unref (mfile);
Packit Service 2a3f3d
  mfile = g_mapped_file_new (to_path, FALSE, error);
Packit Service 2a3f3d
  if (!mfile)
Packit Service 2a3f3d
    goto out;
Packit Service 2a3f3d
  to_bytes = g_mapped_file_get_bytes (mfile);
Packit Service 2a3f3d
  g_mapped_file_unref (mfile);
Packit Service 2a3f3d
Packit Service 2a3f3d
  matches = _ostree_compute_rollsum_matches (from_bytes, to_bytes);
Packit Service 2a3f3d
Packit Service 2a3f3d
  g_printerr ("rollsum crcs=%u bufs=%u total=%u matchsize=%llu\n",
Packit Service 2a3f3d
              matches->crcmatches,
Packit Service 2a3f3d
              matches->bufmatches,
Packit Service 2a3f3d
              matches->total, (unsigned long long)matches->match_size);
Packit Service 2a3f3d
Packit Service 2a3f3d
 out:
Packit Service 2a3f3d
  if (local_error)
Packit Service 2a3f3d
    {
Packit Service 2a3f3d
      g_printerr ("%s\n", local_error->message);
Packit Service 2a3f3d
      return 1;
Packit Service 2a3f3d
    }
Packit Service 2a3f3d
  return 0;
Packit Service 2a3f3d
}