diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..23864ad --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: c +compiler: + - gcc +# - clang +before_install: + - sudo apt-get update -qq + - sudo apt-get install -qq libcurl4-openssl-dev +script: cd c && ./doit.sh && ./testit.sh + +notifications: + irc: "irc.freenode.net#range" + email: false diff --git a/c/Makefile.am b/c/Makefile.am index a4b103a..4bde310 100644 --- a/c/Makefile.am +++ b/c/Makefile.am @@ -10,7 +10,7 @@ zsyncmake_SOURCES = make.c makegz.c makegz.h format_string.h zsyncmake_LDADD = libzsync/libzsync.a librcksum/librcksum.a zlib/libinflate.a zlib/libdeflate.a -lm zsync_SOURCES = client.c http.c http.h url.c url.h progress.c progress.h base64.c format_string.h zsglobal.h -zsync_LDADD = libzsync/libzsync.a librcksum/librcksum.a zlib/libinflate.a $(LIBOBJS) +zsync_LDADD = libzsync/libzsync.a librcksum/librcksum.a zlib/libinflate.a -lcurl $(LIBOBJS) EXTRA_zsync_SOURCES = getaddrinfo.h diff --git a/c/configure.ac b/c/configure.ac index 87b0be1..32aab80 100644 --- a/c/configure.ac +++ b/c/configure.ac @@ -60,7 +60,7 @@ case $host_os in esac AM_CONDITIONAL([MINGW32], test "x$host_os_mingw32" = "xyes") -X_C_COMPILE_FLAGS($ZS_CFLAGS -g -Wall -Wwrite-strings -Winline -Wextra -Winline -Wmissing-noreturn -Wredundant-decls -Wnested-externs -Wundef -Wbad-function-cast -Wcast-align -Wvolatile-register-var -ffast-math) +#X_C_COMPILE_FLAGS($ZS_CFLAGS -g -Wall -Wwrite-strings -Winline -Wextra -Winline -Wmissing-noreturn -Wredundant-decls -Wnested-externs -Wundef -Wbad-function-cast -Wcast-align -Wvolatile-register-var -ffast-math) dnl --- output AC_SUBST(ac_aux_dir) diff --git a/c/doit.sh b/c/doit.sh new file mode 100755 index 0000000..d0b3fc1 --- /dev/null +++ b/c/doit.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -e +set -x +export DESTDIR=$HOME/prefix + +rm -rf $DESTDIR || exit 1 +make clean || true # ignore failures + +aclocal || exit 1 +#libtoolize --force || exit 1 +autoheader || exit 1 +automake -a || exit 1 +autoconf || exit 1 +./configure --prefix=/usr || exit 1 +make || exit 1 +make install || exit 1 + diff --git a/c/index.yaml b/c/index.yaml new file mode 100644 index 0000000..f1a66c7 --- /dev/null +++ b/c/index.yaml @@ -0,0 +1,5 @@ +default: + name: zsync + version: 0.6.2 + summary: 'http based rsync style file fetching with precomputed checksums' + sourcedir: . diff --git a/c/make.c b/c/make.c index 191b527..54099bd 100644 --- a/c/make.c +++ b/c/make.c @@ -585,7 +585,7 @@ int main(int argc, char **argv) { { /* Options parsing */ int opt; - while ((opt = getopt(argc, argv, "b:Ceo:f:u:U:vVzZ")) != -1) { + while ((opt = getopt(argc, argv, "b:Ceo:f:s:u:U:vVzZ")) != -1) { switch (opt) { case 'e': do_exact = 1; @@ -637,31 +637,29 @@ int main(int argc, char **argv) { case 'Z': no_look_inside = 1; break; - } - } - - /* Open data to create .zsync for - either it's a supplied filename, or stdin */ - if (optind == argc - 1) { - infname = strdup(argv[optind]); - instream = fopen(infname, "rb"); - if (!instream) { - perror("open"); - exit(2); - } - - { /* Get mtime if available */ - struct stat st; - if (fstat(fileno(instream), &st) == 0) { - mtime = st.st_mtime; + case 's': + /* Open data to create .zsync its supplied filename */ + infname = strdup(optarg); + instream = fopen(infname, "rb"); + if (!instream) { + perror("open"); + exit(2); } + { + struct stat st; + if (fstat(fileno(instream), &st) == 0) { + mtime = st.st_mtime; + } + } + if (!fname) + fname = basename(optarg); + break; } - - /* Use supplied filename as the target filename */ - if (!fname) - fname = basename(argv[optind]); } - else { - instream = stdin; + + if (!instream) { + printf("ERR: -s infile required\n"); + exit(2); } } diff --git a/c/scripts/build b/c/scripts/build new file mode 100755 index 0000000..2882910 --- /dev/null +++ b/c/scripts/build @@ -0,0 +1,9 @@ +#!/bin/sh + +aclocal +autoheader +automake --add-missing +autoconf +./configure --prefix=/usr +make install LDFLAGS='-lcurl' DESTDIR="$DESTDIR" + diff --git a/c/t/zsyncmake.t b/c/t/zsyncmake.t new file mode 100755 index 0000000..0877f56 --- /dev/null +++ b/c/t/zsyncmake.t @@ -0,0 +1,39 @@ +#!/usr/bin/perl -w + +use warnings; +use strict; + +use Test::More qw(no_plan); +use FindBin; +use File::Temp; + +my $build_root = $ENV{DESTDIR} || "$ENV{HOME}/prefix"; +my $zsm = "$build_root/usr/bin/zsyncmake"; + +my ($small_data_file_fh, $small_data_file) = File::Temp::tempfile(); +my ($medium_data_file_fh, $medium_data_file) = File::Temp::tempfile(); + +print $small_data_file_fh "hello world\n" x 8; +close $small_data_file_fh; + +for (1..1024) { + print $medium_data_file_fh "hello world\n" x 8; +} +close $medium_data_file_fh; + +is(`cat $small_data_file|md5sum`, + "c206bfeb596f75167b404119249403e1 -\n", + "test that our small setup file was generated properly",); + +like( `$zsm -s $small_data_file -o /dev/stdout -u relative/url/path`, + qr! + Filename:\s\w+\s+ + MTime:\s\w+, \s \d+ \s \w+ \s \d+ \s [0-9:]+ \s \+\d+ \s+ + Blocksize: \s 2048 \s+ + Length: \s 96 \s+ + Hash-Lengths: \s 1,2,4 \s+ + URL: \s relative/url/path \s+ + SHA-1: \s \w{40} + !mx, + "zsyncmake small_data_file"); + diff --git a/c/testit.sh b/c/testit.sh new file mode 100755 index 0000000..dc2074f --- /dev/null +++ b/c/testit.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +cd t +for i in *.t; do ./$i || exit 1; done