Skip to content

Commit

Permalink
Fix tar2db breaking with --tar-include/exclude #561
Browse files Browse the repository at this point in the history
We were not correctly updating the position in the tar file, when files were skipped
  • Loading branch information
milot-mirdita committed Jul 4, 2022
1 parent d155586 commit 7be78c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/microtar/microtar.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ int mtar_read_header(mtar_t *tar, mtar_header_t *h) {
return MTAR_ESUCCESS;
}

int mtar_skip_data(mtar_t *tar) {
int n = round_up(tar->curr_size, 512);
int err = tar->seek(tar, n, SEEK_CUR);
if (err) {
return err;
}
return MTAR_ESUCCESS;
}

int mtar_read_data(mtar_t *tar, void *ptr, size_t size) {
/* Read data */
int err = tar->read(tar, ptr, size);
Expand Down
1 change: 1 addition & 0 deletions lib/microtar/microtar.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ int mtar_close(mtar_t *tar);

int mtar_read_header(mtar_t *tar, mtar_header_t *h);
int mtar_read_data(mtar_t *tar, void *ptr, size_t size);
int mtar_skip_data(mtar_t *tar);

#ifdef __cplusplus
}
Expand Down
8 changes: 8 additions & 0 deletions src/util/tar2db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ int tar2db(int argc, const char **argv, const Command& command) {
}
if (header.type == MTAR_TREG || header.type == MTAR_TCONT || header.type == MTAR_TOLDREG) {
if (include.isMatch(name.c_str()) == false || exclude.isMatch(name.c_str()) == true) {
if (header.size > 0 && mtar_skip_data(&tar) != MTAR_ESUCCESS) {
Debug(Debug::ERROR) << "Cannot skip entry " << name << "\n";
EXIT(EXIT_FAILURE);
}
__sync_fetch_and_add(&(globalKey), 1);
proceed = true;
writeEntry = false;
Expand All @@ -194,6 +198,10 @@ int tar2db(int argc, const char **argv, const Command& command) {
currentKey = __sync_fetch_and_add(&(globalKey), 1);
}
} else {
if (header.size > 0 && mtar_skip_data(&tar) != MTAR_ESUCCESS) {
Debug(Debug::ERROR) << "Cannot skip entry " << name << "\n";
EXIT(EXIT_FAILURE);
}
proceed = true;
writeEntry = false;
}
Expand Down

0 comments on commit 7be78c8

Please sign in to comment.