Skip to content

Commit

Permalink
need to rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ksrodarmer committed Mar 16, 2016
1 parent 9584830 commit 8e2ff95
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 3 deletions.
1 change: 1 addition & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ SUBDIRS = \
vdb-dump \
ref-variation \
vdb-validate \
kar \

# under construction
# ngs-pileup \
Expand Down
48 changes: 48 additions & 0 deletions test/kar/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# ===========================================================================
#
# PUBLIC DOMAIN NOTICE
# National Center for Biotechnology Information
#
# This software/database is a "United States Government Work" under the
# terms of the United States Copyright Act. It was written as part of
# the author's official duties as a United States Government employee and
# thus cannot be copyrighted. This software/database is freely available
# to the public for use. The National Library of Medicine and the U.S.
# Government have not placed any restriction on its use or reproduction.
#
# Although all reasonable efforts have been taken to ensure the accuracy
# and reliability of the software and data, the NLM and the U.S.
# Government do not and cannot warrant the performance or results that
# may be obtained by using this software or data. The NLM and the U.S.
# Government disclaim all warranties, express or implied, including
# warranties of performance, merchantability or fitness for any particular
# purpose.
#
# Please cite the author in any work or product based on this material.
#
# ===========================================================================

default: runtests

TOP ?= $(abspath ../..)

MODULE = test/fastq-loader

TEST_TOOLS = \

include $(TOP)/build/Makefile.env

$(TEST_TOOLS): makedirs
@ $(MAKE_CMD) $(TEST_BINDIR)/$@

.PHONY: $(TEST_TOOLS)

clean: stdclean

#-------------------------------------------------------------------------------
# scripted tests
#
runtests: kar_md5

kar_md5: test-kar.sh
@ bash test-kar.sh
51 changes: 51 additions & 0 deletions test/kar/test-kar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
# ===========================================================================
#
# PUBLIC DOMAIN NOTICE
# National Center for Biotechnology Information
#
# This software/database is a "United States Government Work" under the
# terms of the United States Copyright Act. It was written as part of
# the author's official duties as a United States Government employee and
# thus cannot be copyrighted. This software/database is freely available
# to the public for use. The National Library of Medicine and the U.S.
# Government have not placed any restriction on its use or reproduction.
#
# Although all reasonable efforts have been taken to ensure the accuracy
# and reliability of the software and data, the NLM and the U.S.
# Government do not and cannot warrant the performance or results that
# may be obtained by using this software or data. The NLM and the U.S.
# Government disclaim all warranties, express or implied, including
# warranties of performance, merchantability or fitness for any particular
# purpose.
#
# Please cite the author in any work or product based on this material.
#
# ===========================================================================


WORKDIR="./testsource"
ARCHIVE="kar.kar"

kar --md5 -f -d $WORKDIR -c $ARCHIVE

#cat $ARCHIVE.md5

case $(uname) in
(Linux)
md5sum -c $ARCHIVE.md5
;;
(Darwin)
MD5=$(md5 $ARCHIVE)
MY_MD5=$(cut -f1 -d' ' $ARCHIVE.md5)
if [ "$MD5" == "$MY_MD5" ]
then
echo "$ARCHIVE: OK"
else
echo "$ARCHIVE: FAILED"
fi
;;
(*)
echo unknown platform
;;
esac
70 changes: 67 additions & 3 deletions tools/kar/kar.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <kfs/tar.h>
#include <kfs/toc.h>
#include <kfs/sra.h>
#include <kfs/md5.h>
#include <klib/log.h>
#include <klib/out.h>
#include <klib/status.h>
Expand Down Expand Up @@ -69,6 +70,7 @@ KDirectory * kdir;
#define OPTION_LONGLIST "long-list"
#define OPTION_DIRECTORY "directory"
#define OPTION_ALIGN "align"
#define OPTION_MD5 "md5"

#define ALIAS_CREATE "c"
#define ALIAS_TEST "t"
Expand Down Expand Up @@ -105,6 +107,8 @@ static const char * align_usage[] =
static const char * longlist_usage[] =
{ "more information will be given on each file",
"in test/list mode.", NULL };
static const char * md5_usage[] = { "create md5sum-compatible checksum file", NULL };


OptDef Options[] =
{
Expand All @@ -115,7 +119,8 @@ OptDef Options[] =
{ OPTION_FORCE, ALIAS_FORCE, NULL, force_usage, 0, false, false },
{ OPTION_LONGLIST, ALIAS_LONGLIST, NULL, longlist_usage, 0, false, false },
{ OPTION_DIRECTORY, ALIAS_DIRECTORY, NULL, directory_usage, 1, true, false },
{ OPTION_ALIGN, ALIAS_ALIGN, NULL, align_usage, 1, true, false }
{ OPTION_ALIGN, ALIAS_ALIGN, NULL, align_usage, 1, true, false },
{ OPTION_MD5, NULL, NULL, md5_usage, 0, false, false }
};

const char UsageDefaultName[] = "kar";
Expand Down Expand Up @@ -181,6 +186,7 @@ rc_t CC Usage (const Args * args)
HelpOptionLine (ALIAS_FORCE, OPTION_FORCE, NULL, force_usage);
HelpOptionLine (ALIAS_ALIGN, OPTION_ALIGN, "alignment", align_usage);
HelpOptionLine (ALIAS_LONGLIST, OPTION_LONGLIST, NULL, longlist_usage);
HelpOptionLine (NULL, OPTION_MD5, NULL, md5_usage);

HelpOptionsStandard ();

Expand Down Expand Up @@ -228,6 +234,8 @@ static
bool long_list;
static
bool force;
static
bool md5sum;

static
KSRAFileAlignment alignment;
Expand Down Expand Up @@ -541,10 +549,61 @@ rc_t open_out_file (const char * path, KFile ** fout)
}
if (rc == 0)
{
rc = KDirectoryVCreateFile (kdir, fout, false, 0664,
mode, path, NULL);
rc = KDirectoryCreateFile (kdir, fout, false, 0664,
mode, "%s", path);
if (rc)
PLOGERR (klogFatal, (klogFatal, rc, "unable to create archive [$(A)]", PLOG_S(A), path));
else if ( md5sum )
{
KFile *md5_f;

/* create the *.md5 file to hold md5sum-compatible checksum */
rc = KDirectoryCreateFile ( kdir, &md5_f, false, 0664, mode, "%s.md5", path );
if ( rc )
PLOGERR (klogFatal, (klogFatal, rc, "unable to create md5 file [$(A).md5]", PLOG_S(A), path));
else
{
KMD5SumFmt *fmt;

/* create md5 formatter to write to md5_f */
rc = KMD5SumFmtMakeUpdate ( &fmt, md5_f );
if ( rc )
LOGERR (klogErr, rc, "failed to make KMD5SumFmt");
else
{
KMD5File *kmd5_f;

size_t size = string_size ( path );
const char *fname = string_rchr ( path, size, '/' );
if ( fname ++ == NULL )
fname = path;

/* KMD5SumFmtMakeUpdate() took over ownership of "md5_f" */
md5_f = NULL;

/* create a file that knows how to calculate md5 as data
are written-through to archive, and then write digest
result to fmt, using "fname" as description. */
rc = KMD5FileMakeWrite ( &kmd5_f, * fout, fmt, fname );
KMD5SumFmtRelease ( fmt );
if ( rc )
LOGERR (klogErr, rc, "failed to make KMD5File");
else
{
/* success */
*fout = KMD5FileToKFile ( kmd5_f );
return 0;
}
}

/* error cleanup */
KFileRelease ( md5_f );
}

/* error cleanup */
KFileRelease ( * fout );
* fout = NULL;
}
}
return rc;
}
Expand Down Expand Up @@ -1405,6 +1464,11 @@ rc_t CC KMain ( int argc, char *argv [] )
break;
force = (pcount != 0);

rc = ArgsOptionCount (args, OPTION_MD5, &pcount);
if (rc)
break;
md5sum = (pcount != 0);

mode = OM_NONE;

rc = ArgsOptionCount (args, OPTION_DIRECTORY, &pcount);
Expand Down

0 comments on commit 8e2ff95

Please sign in to comment.