Skip to content

Commit

Permalink
fixed a bug that wouldn't find a files full path
Browse files Browse the repository at this point in the history
  • Loading branch information
ksrodarmer committed Jun 13, 2016
1 parent f27bbf4 commit d1e0dfc
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 33 deletions.
1 change: 1 addition & 0 deletions test/kar/kar_testsource/d1/f1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd vi
1 change: 1 addition & 0 deletions test/kar/kar_testsource/d1/f2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd vi sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd v
1 change: 1 addition & 0 deletions test/kar/kar_testsource/d1/f3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd vi sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd v sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd v
1 change: 1 addition & 0 deletions test/kar/kar_testsource/d2/d1/f1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd vi
1 change: 1 addition & 0 deletions test/kar/kar_testsource/d2/d1/f2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd vi sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd v
1 change: 1 addition & 0 deletions test/kar/kar_testsource/d2/d1/f3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd vi sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd v sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd v
1 change: 1 addition & 0 deletions test/kar/kar_testsource/d3/d2/d1/f1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd vi
1 change: 1 addition & 0 deletions test/kar/kar_testsource/d3/d2/d1/f2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd vi sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd v
1 change: 1 addition & 0 deletions test/kar/kar_testsource/d3/d2/d1/f3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd vi sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd v sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd v
1 change: 1 addition & 0 deletions test/kar/kar_testsource/f1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd vi
1 change: 1 addition & 0 deletions test/kar/kar_testsource/f2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd vi sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd v
1 change: 1 addition & 0 deletions test/kar/kar_testsource/f3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd vi sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd v sdfkjas;dfl lkajsdf ;lkajsd fajsd kjaskdjhf aisdhc askjdc lakscsc lshdiasbcasbhd v
21 changes: 2 additions & 19 deletions test/kar/test-kar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,19 @@
# ===========================================================================


TESTDIR="./kar_testsource"
TESTDIR="kar_testsource"
ARCHIVE="kar.kar"

KAR=kar
[ $# -ge 1 ] && KAR="$1"

testdir_setup ()
{
if ! mkdir $TESTDIR
then
echo "Failed to create testsource"
exit 1
fi

echo "random text for test purposes" > $TESTDIR/test_file1
echo "random text for test purposes and more" > $TESTDIR/test_file2
}

cleanup ()
{
rm -rf $TESTDIR $ARCHIVE $ARCHIVE.md5
rm -rf $ARCHIVE $ARCHIVE.md5
}


# if test source directory doesnt exist, make it and populate it
if [ ! -d $TESTDIR ]
then
testdir_setup
fi

# run the script
if ! $KAR --md5 -f -c $ARCHIVE -d $TESTDIR
then
Expand Down
33 changes: 19 additions & 14 deletions tools/kar/kar.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ rc_t kar_entry_create ( KAREntry ** rtn, size_t entry_size,
if ( entry == NULL )
{
rc = RC (rcExe, rcNode, rcAllocating, rcMemory, rcExhausted);
pLogErr ( klogErr, rc, "Failed to allocated memory for entry $(name)",
pLogErr ( klogErr, rc, "Failed to allocated memory for entry '$(name)'",
"name=%s", name );
}
else
Expand All @@ -212,15 +212,15 @@ rc_t kar_entry_create ( KAREntry ** rtn, size_t entry_size,
rc = KDirectoryAccess ( dir, & entry -> access_mode, "%s", entry -> name );
if ( rc != 0 )
{
pLogErr ( klogErr, rc, "Failed to get access mode for entry $(name)",
pLogErr ( klogErr, rc, "Failed to get access mode for entry '$(name)'",
"name=%s", entry -> name );
}
else
{
rc = KDirectoryDate ( dir, &entry -> mod_time, "%s", entry -> name );
if ( rc != 0 )
{
pLogErr ( klogErr, rc, "Failed to get modification for entry $(name)",
pLogErr ( klogErr, rc, "Failed to get modification for entry '$(name)'",
"name=%s", entry -> name );
}
else
Expand All @@ -247,7 +247,7 @@ rc_t kar_entry_inflate ( KAREntry **rtn, size_t entry_size, const char *name, si
if ( entry == NULL )
{
rc = RC (rcExe, rcNode, rcAllocating, rcMemory, rcExhausted);
pLogErr ( klogErr, rc, "Failed to allocated memory for entry $(name)",
pLogErr ( klogErr, rc, "Failed to allocated memory for entry '$(name)'",
"name=%s", name );
}
else
Expand Down Expand Up @@ -859,21 +859,27 @@ rc_t kar_prepare_toc ( const BSTree *tree, KARFilePtrArray *file_array_ptr )
}

static
size_t kar_entry_full_path ( const KAREntry * entry, char * buffer, size_t bsize )
size_t kar_entry_full_path ( const KAREntry * entry, const char * root_dir, char * buffer, size_t bsize )
{
size_t offset = 0;
if ( entry -> parentDir != NULL )
{
offset = kar_entry_full_path ( & entry -> parentDir -> dad, buffer, bsize );
offset = kar_entry_full_path ( & entry -> parentDir -> dad, root_dir, buffer, bsize );
if ( offset < bsize )
buffer [ offset ++ ] = '/';
}
else if ( root_dir != NULL && root_dir [ 0 ] != 0 )
{
offset = string_copy_measure ( buffer, bsize, root_dir );
if ( buffer [ offset - 1 ] != '/' && offset < bsize )
buffer [ offset ++ ] = '/';
}

return string_copy_measure ( & buffer [ offset ], bsize - offset, entry -> name ) + offset;
}

static
void kar_write_file ( KARArchiveFile *af, const KDirectory *wd, const KARFile *file )
void kar_write_file ( KARArchiveFile *af, const KDirectory *wd, const KARFile *file, const char * root_dir )
{
rc_t rc;
char *buffer;
Expand All @@ -895,7 +901,7 @@ void kar_write_file ( KARArchiveFile *af, const KDirectory *wd, const KARFile *f

STATUS ( STAT_QA, "writing file '%s'", file -> dad . name );

path_size = kar_entry_full_path ( & file -> dad, filename, sizeof filename );
path_size = kar_entry_full_path ( & file -> dad, root_dir, filename, sizeof filename );
if ( path_size == sizeof filename )
{
/* path name was somehow too long */
Expand All @@ -908,7 +914,7 @@ void kar_write_file ( KARArchiveFile *af, const KDirectory *wd, const KARFile *f
rc = KDirectoryOpenFileRead ( wd, &f, "%s", filename );
if ( rc != 0 )
{
pLogErr ( klogInt, rc, "Failed to open file %s", file -> dad . name );
pLogErr ( klogInt, rc, "Failed to open file $(fname)", "fname=%s", file -> dad . name );
exit (6);
}

Expand All @@ -917,7 +923,7 @@ void kar_write_file ( KARArchiveFile *af, const KDirectory *wd, const KARFile *f
if ( buffer == NULL )
{
rc = RC ( rcExe, rcFile, rcWriting, rcMemory, rcExhausted );
pLogErr ( klogInt, rc, "Failed to open file %s", file -> dad . name );
pLogErr ( klogInt, rc, "Failed to open file $(fname)", "fname=%s", file -> dad . name );
exit ( 7 );
}

Expand Down Expand Up @@ -960,7 +966,7 @@ void kar_write_file ( KARArchiveFile *af, const KDirectory *wd, const KARFile *f
}

static
rc_t kar_make ( const KDirectory * wd, KFile *archive, const BSTree *tree )
rc_t kar_make ( const KDirectory * wd, KFile *archive, const BSTree *tree, const char * root_dir )
{
rc_t rc = 0;

Expand All @@ -971,7 +977,6 @@ rc_t kar_make ( const KDirectory * wd, KFile *archive, const BSTree *tree )
{
uint64_t i, toc_size;
KARArchiveFile af;

/* evaluate toc size */
toc_size = kar_eval_toc_size ( tree );

Expand All @@ -990,7 +995,7 @@ rc_t kar_make ( const KDirectory * wd, KFile *archive, const BSTree *tree )
for ( i = 0; i < num_files; ++ i )
{
STATUS ( STAT_QA, "writing file %u: '%s'", i, file_array [ i ] -> dad . name );
kar_write_file ( & af, wd, file_array [ i ] );
kar_write_file ( & af, wd, file_array [ i ], root_dir );
}

free ( file_array );
Expand Down Expand Up @@ -1048,7 +1053,7 @@ rc_t kar_create ( const Params *p )
{
BSTreeForEach ( &tree, false, kar_entry_link_parent_dir, NULL );

rc = kar_make ( wd, archive, &tree );
rc = kar_make ( wd, archive, &tree, p -> directory_path );
if ( rc != 0 )
LogErr ( klogInt, rc, "Failed to build archive" );
}
Expand Down

0 comments on commit d1e0dfc

Please sign in to comment.