2017-09-21 22:26:06 +03:00
/*
2013-08-15 17:14:26 +04:00
* Copyright ( C ) 2013 Colin Walters < walters @ verbum . org >
*
2018-01-30 22:26:26 +03:00
* SPDX - License - Identifier : LGPL - 2.0 +
*
2013-08-15 17:14:26 +04:00
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
2021-12-07 04:20:55 +03:00
* License along with this library . If not , see < https : //www.gnu.org/licenses/>.
2013-08-15 17:14:26 +04:00
*/
# include "config.h"
2015-01-30 18:13:07 +03:00
# include "ostree-rollsum.h"
2014-02-10 01:11:37 +04:00
2017-03-23 20:06:07 +03:00
# include "libglnx.h"
2013-08-15 17:14:26 +04:00
int
main ( int argc , char * * argv )
{
2023-05-01 21:24:29 +03:00
g_autoptr ( GError ) local_error = NULL ;
2013-08-15 17:14:26 +04:00
GError * * error = & local_error ;
2015-01-30 18:13:07 +03:00
GBytes * from_bytes = NULL ;
GBytes * to_bytes = NULL ;
const char * from_path ;
const char * to_path ;
OstreeRollsumMatches * matches ;
GMappedFile * mfile ;
2013-08-15 17:14:26 +04:00
2022-01-10 13:22:28 +03:00
gboolean is_ok = g_setenv ( " GIO_USE_VFS " , " local " , TRUE ) ;
g_assert ( is_ok = = TRUE ) ;
2013-08-15 17:14:26 +04:00
2015-01-30 18:13:07 +03:00
if ( argc < 3 )
2017-03-11 00:24:57 +03:00
return 1 ;
2013-08-15 17:14:26 +04:00
2015-01-30 18:13:07 +03:00
from_path = argv [ 1 ] ;
to_path = argv [ 2 ] ;
2013-08-15 17:14:26 +04:00
2015-01-30 18:13:07 +03:00
mfile = g_mapped_file_new ( from_path , FALSE , error ) ;
if ( ! mfile )
goto out ;
from_bytes = g_mapped_file_get_bytes ( mfile ) ;
g_mapped_file_unref ( mfile ) ;
mfile = g_mapped_file_new ( to_path , FALSE , error ) ;
if ( ! mfile )
goto out ;
to_bytes = g_mapped_file_get_bytes ( mfile ) ;
g_mapped_file_unref ( mfile ) ;
2014-02-10 01:11:37 +04:00
2015-01-30 18:13:07 +03:00
matches = _ostree_compute_rollsum_matches ( from_bytes , to_bytes ) ;
2014-02-10 01:11:37 +04:00
2023-05-01 21:24:29 +03:00
g_printerr ( " rollsum crcs=%u bufs=%u total=%u matchsize=%llu \n " , matches - > crcmatches ,
matches - > bufmatches , matches - > total , ( unsigned long long ) matches - > match_size ) ;
2013-08-15 17:14:26 +04:00
2023-05-01 21:24:29 +03:00
out :
2013-08-15 17:14:26 +04:00
if ( local_error )
{
g_printerr ( " %s \n " , local_error - > message ) ;
return 1 ;
}
return 0 ;
}