untar changed to allow deb_extract to extract to memory, allows better operation of dpkg-deb -f
This commit is contained in:
parent
a529d885d2
commit
685f5fd6f4
@ -239,7 +239,9 @@ typedef enum extract_function_e {
|
|||||||
extract_field = 128
|
extract_field = 128
|
||||||
} extract_function_t;
|
} extract_function_t;
|
||||||
extern int deb_extract(const char *package_filename, int function, char *target_dir);
|
extern int deb_extract(const char *package_filename, int function, char *target_dir);
|
||||||
extern int untar(FILE *src_tar_file, const int untar_function, const char *argument);
|
extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, const char *argument);
|
||||||
|
extern char *read_text_file_to_buffer(FILE *src_file);
|
||||||
|
extern char *read_package_field(const char *package_buffer);
|
||||||
|
|
||||||
extern int unzip(FILE *l_in_file, FILE *l_out_file);
|
extern int unzip(FILE *l_in_file, FILE *l_out_file);
|
||||||
extern void gz_close(int gunzip_pid);
|
extern void gz_close(int gunzip_pid);
|
||||||
|
@ -75,11 +75,24 @@ extern int deb_extract(const char *package_filename, int function, char *argumen
|
|||||||
if (function & extract_fsys_tarfile) {
|
if (function & extract_fsys_tarfile) {
|
||||||
copy_file_chunk(uncompressed_file, stdout, -1);
|
copy_file_chunk(uncompressed_file, stdout, -1);
|
||||||
} else {
|
} else {
|
||||||
untar(uncompressed_file, function, argument);
|
char *output_buffer = NULL;
|
||||||
|
output_buffer = untar(uncompressed_file, stdout, function, argument);
|
||||||
|
if (function & extract_field) {
|
||||||
|
char *field = NULL;
|
||||||
|
int field_length = 0;
|
||||||
|
int field_start = 0;
|
||||||
|
while ((field = read_package_field(&output_buffer[field_start])) != NULL) {
|
||||||
|
field_length = strlen(field);
|
||||||
|
field_start += (field_length + 1);
|
||||||
|
if (strstr(field, argument) == field) {
|
||||||
|
printf("%s\n", field + strlen(argument) + 2);
|
||||||
|
}
|
||||||
|
free(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* we are deliberately terminating the child so we can safely ignore this */
|
|
||||||
gz_close(gunzip_pid);
|
|
||||||
|
|
||||||
|
gz_close(gunzip_pid);
|
||||||
fclose(deb_file);
|
fclose(deb_file);
|
||||||
fclose(uncompressed_file);
|
fclose(uncompressed_file);
|
||||||
free(ared_file);
|
free(ared_file);
|
||||||
|
@ -239,7 +239,9 @@ typedef enum extract_function_e {
|
|||||||
extract_field = 128
|
extract_field = 128
|
||||||
} extract_function_t;
|
} extract_function_t;
|
||||||
extern int deb_extract(const char *package_filename, int function, char *target_dir);
|
extern int deb_extract(const char *package_filename, int function, char *target_dir);
|
||||||
extern int untar(FILE *src_tar_file, const int untar_function, const char *argument);
|
extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, const char *argument);
|
||||||
|
extern char *read_text_file_to_buffer(FILE *src_file);
|
||||||
|
extern char *read_package_field(const char *package_buffer);
|
||||||
|
|
||||||
extern int unzip(FILE *l_in_file, FILE *l_out_file);
|
extern int unzip(FILE *l_in_file, FILE *l_out_file);
|
||||||
extern void gz_close(int gunzip_pid);
|
extern void gz_close(int gunzip_pid);
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
extern int untar(FILE *src_tar_file, const int untar_function, const char *argument)
|
extern char *untar(FILE *src_tar_file, FILE *output, const int untar_function, const char *argument)
|
||||||
{
|
{
|
||||||
typedef struct raw_tar_header {
|
typedef struct raw_tar_header {
|
||||||
char name[100]; /* 0-99 */
|
char name[100]; /* 0-99 */
|
||||||
@ -103,13 +103,12 @@ extern int untar(FILE *src_tar_file, const int untar_function, const char *argum
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (untar_function & (extract_contents | extract_verbose_extract)) {
|
if (untar_function & (extract_contents | extract_verbose_extract)) {
|
||||||
printf("%s\n", raw_tar_header.name);
|
fprintf(output, "%s\n", raw_tar_header.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* extract files */
|
/* extract files */
|
||||||
if (untar_function & (extract_extract | extract_verbose_extract | extract_control)) {
|
if (untar_function & (extract_extract | extract_verbose_extract | extract_control)) {
|
||||||
dir = xmalloc(strlen(raw_tar_header.name) + strlen(argument) + 2);
|
dir = concat_path_file(argument, raw_tar_header.name);
|
||||||
sprintf(dir, "%s/%s", argument, raw_tar_header.name);
|
|
||||||
create_path(dir, 0777);
|
create_path(dir, 0777);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,33 +119,27 @@ extern int untar(FILE *src_tar_file, const int untar_function, const char *argum
|
|||||||
* supposed to be a directory, and fall through
|
* supposed to be a directory, and fall through
|
||||||
*/
|
*/
|
||||||
if (raw_tar_header.name[strlen(raw_tar_header.name)-1] != '/') {
|
if (raw_tar_header.name[strlen(raw_tar_header.name)-1] != '/') {
|
||||||
if (untar_function & (extract_extract | extract_verbose_extract | extract_control)) {
|
switch (untar_function) {
|
||||||
|
case (extract_extract):
|
||||||
|
case (extract_verbose_extract):
|
||||||
|
case (extract_control): {
|
||||||
FILE *dst_file = wfopen(dir, "w");
|
FILE *dst_file = wfopen(dir, "w");
|
||||||
copy_file_chunk(src_tar_file, dst_file, (unsigned long long) size);
|
copy_file_chunk(src_tar_file, dst_file, (unsigned long long) size);
|
||||||
uncompressed_count += size;
|
uncompressed_count += size;
|
||||||
fclose(dst_file);
|
fclose(dst_file);
|
||||||
}
|
}
|
||||||
else if (untar_function & extract_info) {
|
break;
|
||||||
|
case (extract_info):
|
||||||
if (strstr(raw_tar_header.name, argument) != NULL) {
|
if (strstr(raw_tar_header.name, argument) != NULL) {
|
||||||
copy_file_chunk(src_tar_file, stdout, (unsigned long long) size);
|
copy_file_chunk(src_tar_file, stdout, (unsigned long long) size);
|
||||||
uncompressed_count += size;
|
uncompressed_count += size;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case (extract_field):
|
||||||
|
if (strstr(raw_tar_header.name, "control") != NULL) {
|
||||||
|
return(read_text_file_to_buffer(src_tar_file));
|
||||||
}
|
}
|
||||||
else if (untar_function & extract_field) {
|
break;
|
||||||
if (strstr(raw_tar_header.name, "./control") != NULL) {
|
|
||||||
char *line;
|
|
||||||
while ((line = get_line_from_file(src_tar_file)) != NULL) {
|
|
||||||
uncompressed_count += strlen(line);
|
|
||||||
if (argument == NULL) {
|
|
||||||
printf("%s",line);
|
|
||||||
}
|
|
||||||
else if (strncmp(line, argument, strlen(argument)) == 0) {
|
|
||||||
char *file_ptr;
|
|
||||||
file_ptr = strstr(line, ": ");
|
|
||||||
printf("%s", file_ptr + 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -155,7 +148,7 @@ extern int untar(FILE *src_tar_file, const int untar_function, const char *argum
|
|||||||
if (create_path(dir, mode) != TRUE) {
|
if (create_path(dir, mode) != TRUE) {
|
||||||
free(dir);
|
free(dir);
|
||||||
perror_msg("%s: Cannot mkdir", raw_tar_header.name);
|
perror_msg("%s: Cannot mkdir", raw_tar_header.name);
|
||||||
return(EXIT_FAILURE);
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -164,7 +157,7 @@ extern int untar(FILE *src_tar_file, const int untar_function, const char *argum
|
|||||||
if (link(raw_tar_header.linkname, raw_tar_header.name) < 0) {
|
if (link(raw_tar_header.linkname, raw_tar_header.name) < 0) {
|
||||||
free(dir);
|
free(dir);
|
||||||
perror_msg("%s: Cannot create hard link to '%s'", raw_tar_header.name, raw_tar_header.linkname);
|
perror_msg("%s: Cannot create hard link to '%s'", raw_tar_header.name, raw_tar_header.linkname);
|
||||||
return(EXIT_FAILURE);
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -173,7 +166,7 @@ extern int untar(FILE *src_tar_file, const int untar_function, const char *argum
|
|||||||
if (symlink(raw_tar_header.linkname, raw_tar_header.name) < 0) {
|
if (symlink(raw_tar_header.linkname, raw_tar_header.name) < 0) {
|
||||||
free(dir);
|
free(dir);
|
||||||
perror_msg("%s: Cannot create symlink to '%s'", raw_tar_header.name, raw_tar_header.linkname);
|
perror_msg("%s: Cannot create symlink to '%s'", raw_tar_header.name, raw_tar_header.linkname);
|
||||||
return(EXIT_FAILURE);
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -186,7 +179,7 @@ extern int untar(FILE *src_tar_file, const int untar_function, const char *argum
|
|||||||
default:
|
default:
|
||||||
error_msg("Unknown file type '%c' in tar file", raw_tar_header.typeflag);
|
error_msg("Unknown file type '%c' in tar file", raw_tar_header.typeflag);
|
||||||
free(dir);
|
free(dir);
|
||||||
return(EXIT_FAILURE);
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -201,5 +194,5 @@ extern int untar(FILE *src_tar_file, const int untar_function, const char *argum
|
|||||||
|
|
||||||
// free(dir);
|
// free(dir);
|
||||||
}
|
}
|
||||||
return(EXIT_SUCCESS);
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user