dpkg-deb -c works now
This commit is contained in:
parent
359c106871
commit
6785b51280
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
extern int dpkg_deb_main(int argc, char **argv)
|
extern int dpkg_deb_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *target_dir = NULL;
|
char *target_dir;
|
||||||
int opt = 0;
|
int opt = 0;
|
||||||
int optflag = 0;
|
int optflag = 0;
|
||||||
|
|
||||||
@ -50,9 +50,10 @@ extern int dpkg_deb_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((optind + 1 ) > argc) || (optflag == 0)) {
|
if (optind == argc) {
|
||||||
show_usage();
|
show_usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (optflag) {
|
switch (optflag) {
|
||||||
case (extract_control):
|
case (extract_control):
|
||||||
case (extract_extract):
|
case (extract_extract):
|
||||||
@ -60,13 +61,15 @@ extern int dpkg_deb_main(int argc, char **argv)
|
|||||||
if ( (optind + 1) == argc ) {
|
if ( (optind + 1) == argc ) {
|
||||||
target_dir = (char *) xmalloc(7);
|
target_dir = (char *) xmalloc(7);
|
||||||
strcpy(target_dir, "DEBIAN");
|
strcpy(target_dir, "DEBIAN");
|
||||||
|
} else {
|
||||||
|
target_dir = (char *) xmalloc(strlen(argv[optind + 1]) + 1);
|
||||||
|
strcpy(target_dir, argv[optind + 1]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: {
|
default:
|
||||||
target_dir = (char *) xmalloc(strlen(argv[optind + 1]));
|
target_dir = NULL;
|
||||||
strcpy(target_dir, argv[optind + 1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deb_extract(argv[optind], optflag, target_dir);
|
deb_extract(argv[optind], optflag, target_dir);
|
||||||
/* else if (optflag & dpkg_deb_info) {
|
/* else if (optflag & dpkg_deb_info) {
|
||||||
extract_flag = TRUE;
|
extract_flag = TRUE;
|
||||||
|
15
dpkg_deb.c
15
dpkg_deb.c
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
extern int dpkg_deb_main(int argc, char **argv)
|
extern int dpkg_deb_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *target_dir = NULL;
|
char *target_dir;
|
||||||
int opt = 0;
|
int opt = 0;
|
||||||
int optflag = 0;
|
int optflag = 0;
|
||||||
|
|
||||||
@ -50,9 +50,10 @@ extern int dpkg_deb_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((optind + 1 ) > argc) || (optflag == 0)) {
|
if (optind == argc) {
|
||||||
show_usage();
|
show_usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (optflag) {
|
switch (optflag) {
|
||||||
case (extract_control):
|
case (extract_control):
|
||||||
case (extract_extract):
|
case (extract_extract):
|
||||||
@ -60,13 +61,15 @@ extern int dpkg_deb_main(int argc, char **argv)
|
|||||||
if ( (optind + 1) == argc ) {
|
if ( (optind + 1) == argc ) {
|
||||||
target_dir = (char *) xmalloc(7);
|
target_dir = (char *) xmalloc(7);
|
||||||
strcpy(target_dir, "DEBIAN");
|
strcpy(target_dir, "DEBIAN");
|
||||||
|
} else {
|
||||||
|
target_dir = (char *) xmalloc(strlen(argv[optind + 1]) + 1);
|
||||||
|
strcpy(target_dir, argv[optind + 1]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: {
|
default:
|
||||||
target_dir = (char *) xmalloc(strlen(argv[optind + 1]));
|
target_dir = NULL;
|
||||||
strcpy(target_dir, argv[optind + 1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deb_extract(argv[optind], optflag, target_dir);
|
deb_extract(argv[optind], optflag, target_dir);
|
||||||
/* else if (optflag & dpkg_deb_info) {
|
/* else if (optflag & dpkg_deb_info) {
|
||||||
extract_flag = TRUE;
|
extract_flag = TRUE;
|
||||||
|
@ -52,18 +52,16 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
|
|||||||
size_t size;
|
size_t size;
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
|
|
||||||
// signal(SIGCHLD, child_died);
|
|
||||||
|
|
||||||
while (fread((char *) &raw_tar_header, 1, 512, src_tar_file) == 512) {
|
while (fread((char *) &raw_tar_header, 1, 512, src_tar_file) == 512) {
|
||||||
long sum = 0;
|
long sum = 0;
|
||||||
char *dir;
|
char *dir = NULL;
|
||||||
|
|
||||||
uncompressed_count += 512;
|
uncompressed_count += 512;
|
||||||
|
|
||||||
/* Check header has valid magic */
|
/* Check header has valid magic */
|
||||||
if (strncmp(raw_tar_header.magic, "ustar", 5) != 0) {
|
if (strncmp(raw_tar_header.magic, "ustar", 5) != 0) {
|
||||||
/* Put this pack after TODO (check child still alive) is done */
|
/* Put this pack after TODO (check child still alive) is done */
|
||||||
// error_msg("Invalid tar magic");
|
error_msg("Invalid tar magic");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,11 +109,16 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
|
|||||||
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
/* extract files */
|
if (untar_function & (extract_verbose_extract | extract_contents)) {
|
||||||
dir = xmalloc(strlen(raw_tar_header.name) + strlen(base_path) + 2);
|
printf("%s\n", raw_tar_header.name);
|
||||||
|
}
|
||||||
|
|
||||||
sprintf(dir, "%s/%s", base_path, raw_tar_header.name);
|
/* extract files */
|
||||||
create_path(dir, 0777);
|
if (base_path != NULL) {
|
||||||
|
dir = xmalloc(strlen(raw_tar_header.name) + strlen(base_path) + 2);
|
||||||
|
sprintf(dir, "%s/%s", base_path, raw_tar_header.name);
|
||||||
|
create_path(dir, 0777);
|
||||||
|
}
|
||||||
switch (raw_tar_header.typeflag ) {
|
switch (raw_tar_header.typeflag ) {
|
||||||
case '0':
|
case '0':
|
||||||
case '\0':
|
case '\0':
|
||||||
@ -124,8 +127,6 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
|
|||||||
*/
|
*/
|
||||||
if (raw_tar_header.name[strlen(raw_tar_header.name)-1] != '/') {
|
if (raw_tar_header.name[strlen(raw_tar_header.name)-1] != '/') {
|
||||||
switch (untar_function) {
|
switch (untar_function) {
|
||||||
case (extract_verbose_extract):
|
|
||||||
printf("%s\n", raw_tar_header.name);
|
|
||||||
case (extract_extract): {
|
case (extract_extract): {
|
||||||
FILE *dst_file = wfopen(dir, "w");
|
FILE *dst_file = wfopen(dir, "w");
|
||||||
copy_file_chunk(src_tar_file, dst_file, size);
|
copy_file_chunk(src_tar_file, dst_file, size);
|
||||||
@ -143,17 +144,12 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '5':
|
case '5':
|
||||||
switch (untar_function) {
|
if (untar_function & (extract_extract | extract_verbose_extract)) {
|
||||||
case (extract_verbose_extract):
|
if (create_path(dir, mode) != TRUE) {
|
||||||
printf("%s\n", raw_tar_header.name);
|
free(dir);
|
||||||
case (extract_extract):
|
perror_msg("%s: Cannot mkdir", raw_tar_header.name);
|
||||||
if (create_path(dir, mode) != TRUE) {
|
return(EXIT_FAILURE);
|
||||||
free(dir);
|
}
|
||||||
perror_msg("%s: Cannot mkdir", raw_tar_header.name);
|
|
||||||
return(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '1':
|
case '1':
|
||||||
@ -185,7 +181,7 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
|
|||||||
free(dir);
|
free(dir);
|
||||||
return(EXIT_FAILURE);
|
return(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
free(dir);
|
// free(dir);
|
||||||
}
|
}
|
||||||
return(EXIT_SUCCESS);
|
return(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user