diff options
author | Rob Landley <rob@landley.net> | 2005-10-27 22:49:08 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2005-10-27 22:49:08 +0000 |
commit | f3d6c94c7f1f88e51a0419cdfc655eeac8856744 (patch) | |
tree | 389bc49a21f1d0b34cd81b1cde3e769f0899295f | |
parent | 47ea7b7f96e0ba76514a4f24177dc0e3e5ec30a0 (diff) | |
download | busybox-w32-f3d6c94c7f1f88e51a0419cdfc655eeac8856744.tar.gz busybox-w32-f3d6c94c7f1f88e51a0419cdfc655eeac8856744.tar.bz2 busybox-w32-f3d6c94c7f1f88e51a0419cdfc655eeac8856744.zip |
Add --no-same-owner and --no-same-permissions options to tar.
-rw-r--r-- | archival/libunarchive/data_extract_all.c | 8 | ||||
-rw-r--r-- | archival/tar.c | 87 | ||||
-rw-r--r-- | include/unarchive.h | 12 |
3 files changed, 65 insertions, 42 deletions
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c index d10d665f6..42e442336 100644 --- a/archival/libunarchive/data_extract_all.c +++ b/archival/libunarchive/data_extract_all.c | |||
@@ -111,8 +111,12 @@ extern void data_extract_all(archive_handle_t *archive_handle) | |||
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | lchown(file_header->name, file_header->uid, file_header->gid); | 114 | if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_OWN)) { |
115 | if ((file_header->mode & S_IFMT) != S_IFLNK) { | 115 | lchown(file_header->name, file_header->uid, file_header->gid); |
116 | } | ||
117 | if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_PERM) && | ||
118 | (file_header->mode & S_IFMT) != S_IFLNK) | ||
119 | { | ||
116 | chmod(file_header->name, file_header->mode); | 120 | chmod(file_header->name, file_header->mode); |
117 | } | 121 | } |
118 | 122 | ||
diff --git a/archival/tar.c b/archival/tar.c index 82a79b728..e486f7fa3 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -578,66 +578,76 @@ static char get_header_tar_Z(archive_handle_t *archive_handle) | |||
578 | #define get_header_tar_Z 0 | 578 | #define get_header_tar_Z 0 |
579 | #endif | 579 | #endif |
580 | 580 | ||
581 | #define CTX_TEST (1 << 0) | 581 | #define CTX_TEST (1 << 0) |
582 | #define CTX_EXTRACT (1 << 1) | 582 | #define CTX_EXTRACT (1 << 1) |
583 | #define TAR_OPT_BASEDIR (1 << 2) | 583 | #define TAR_OPT_BASEDIR (1 << 2) |
584 | #define TAR_OPT_TARNAME (1 << 3) | 584 | #define TAR_OPT_TARNAME (1 << 3) |
585 | #define TAR_OPT_2STDOUT (1 << 4) | 585 | #define TAR_OPT_2STDOUT (1 << 4) |
586 | #define TAR_OPT_P (1 << 5) | 586 | #define TAR_OPT_P (1 << 5) |
587 | #define TAR_OPT_VERBOSE (1 << 6) | 587 | #define TAR_OPT_VERBOSE (1 << 6) |
588 | #define TAR_OPT_KEEP_OLD (1 << 7) | 588 | #define TAR_OPT_KEEP_OLD (1 << 7) |
589 | 589 | ||
590 | # define CTX_CREATE (1 << 8) | 590 | #define TAR_OPT_AFTER_START 8 |
591 | # define TAR_OPT_DEREFERNCE (1 << 9) | 591 | |
592 | #define CTX_CREATE (1 << (TAR_OPT_AFTER_START)) | ||
593 | #define TAR_OPT_DEREFERNCE (1 << (TAR_OPT_AFTER_START + 1)) | ||
592 | #ifdef CONFIG_FEATURE_TAR_CREATE | 594 | #ifdef CONFIG_FEATURE_TAR_CREATE |
593 | # define TAR_OPT_STR_CREATE "ch" | 595 | # define TAR_OPT_STR_CREATE "ch" |
594 | # define TAR_OPT_FLAG_CREATE 2 | 596 | # define TAR_OPT_AFTER_CREATE TAR_OPT_AFTER_START + 2 |
595 | #else | 597 | #else |
596 | # define TAR_OPT_STR_CREATE "" | 598 | # define TAR_OPT_STR_CREATE "" |
597 | # define TAR_OPT_FLAG_CREATE 0 | 599 | # define TAR_OPT_AFTER_CREATE TAR_OPT_AFTER_START |
598 | #endif | 600 | #endif |
599 | 601 | ||
600 | # define TAR_OPT_BZIP2 (1 << (8 + TAR_OPT_FLAG_CREATE)) | 602 | #define TAR_OPT_BZIP2 (1 << (TAR_OPT_AFTER_CREATE)) |
601 | #ifdef CONFIG_FEATURE_TAR_BZIP2 | 603 | #ifdef CONFIG_FEATURE_TAR_BZIP2 |
602 | # define TAR_OPT_STR_BZIP2 "j" | 604 | # define TAR_OPT_STR_BZIP2 "j" |
603 | # define TAR_OPT_FLAG_BZIP2 1 | 605 | # define TAR_OPT_AFTER_BZIP2 TAR_OPT_AFTER_CREATE + 1 |
604 | #else | 606 | #else |
605 | # define TAR_OPT_STR_BZIP2 "" | 607 | # define TAR_OPT_STR_BZIP2 "" |
606 | # define TAR_OPT_FLAG_BZIP2 0 | 608 | # define TAR_OPT_AFTER_BZIP2 TAR_OPT_AFTER_CREATE |
607 | #endif | 609 | #endif |
608 | 610 | ||
609 | # define TAR_OPT_INCLUDE_FROM (1 << (8 + TAR_OPT_FLAG_CREATE + TAR_OPT_FLAG_BZIP2)) | 611 | #define TAR_OPT_INCLUDE_FROM (1 << (TAR_OPT_AFTER_BZIP2)) |
610 | # define TAR_OPT_EXCLUDE_FROM (1 << (8 + TAR_OPT_FLAG_CREATE + TAR_OPT_FLAG_BZIP2 + 1)) | 612 | #define TAR_OPT_EXCLUDE_FROM (1 << (TAR_OPT_AFTER_BZIP2 + 1)) |
611 | #ifdef CONFIG_FEATURE_TAR_FROM | 613 | #ifdef CONFIG_FEATURE_TAR_FROM |
612 | # define TAR_OPT_STR_FROM "T:X:" | 614 | # define TAR_OPT_STR_FROM "T:X:" |
613 | # define TAR_OPT_FLAG_FROM 2 | 615 | # define TAR_OPT_AFTER_FROM TAR_OPT_AFTER_BZIP2 + 2 |
614 | #else | 616 | #else |
615 | # define TAR_OPT_STR_FROM "" | 617 | # define TAR_OPT_STR_FROM "" |
616 | # define TAR_OPT_FLAG_FROM 0 | 618 | # define TAR_OPT_AFTER_FROM TAR_OPT_AFTER_BZIP2 |
617 | #endif | 619 | #endif |
618 | 620 | ||
619 | # define TAR_OPT_GZIP (1 << (8 + TAR_OPT_FLAG_CREATE + TAR_OPT_FLAG_BZIP2 + TAR_OPT_FLAG_FROM)) | 621 | #define TAR_OPT_GZIP (1 << (TAR_OPT_AFTER_FROM)) |
620 | #ifdef CONFIG_FEATURE_TAR_GZIP | 622 | #ifdef CONFIG_FEATURE_TAR_GZIP |
621 | # define TAR_OPT_STR_GZIP "z" | 623 | # define TAR_OPT_STR_GZIP "z" |
622 | # define TAR_OPT_FLAG_GZIP 1 | 624 | # define TAR_OPT_AFTER_GZIP TAR_OPT_AFTER_FROM + 1 |
623 | #else | 625 | #else |
624 | # define TAR_OPT_STR_GZIP "" | 626 | # define TAR_OPT_STR_GZIP "" |
625 | # define TAR_OPT_FLAG_GZIP 0 | 627 | # define TAR_OPT_AFTER_GZIP TAR_OPT_AFTER_FROM |
626 | #endif | 628 | #endif |
627 | 629 | ||
628 | # define TAR_OPT_UNCOMPRESS (1 << (8 + TAR_OPT_FLAG_CREATE + TAR_OPT_FLAG_BZIP2 + TAR_OPT_FLAG_FROM + TAR_OPT_FLAG_GZIP)) | 630 | #define TAR_OPT_UNCOMPRESS (1 << (TAR_OPT_AFTER_GZIP)) |
629 | #ifdef CONFIG_FEATURE_TAR_COMPRESS | 631 | #ifdef CONFIG_FEATURE_TAR_COMPRESS |
630 | # define TAR_OPT_STR_COMPRESS "Z" | 632 | # define TAR_OPT_STR_COMPRESS "Z" |
633 | # define TAR_OPT_AFTER_COMPRESS TAR_OPT_AFTER_GZIP + 1 | ||
631 | #else | 634 | #else |
632 | # define TAR_OPT_STR_COMPRESS "" | 635 | # define TAR_OPT_STR_COMPRESS "" |
636 | # define TAR_OPT_AFTER_COMPRESS TAR_OPT_AFTER_GZIP | ||
633 | #endif | 637 | #endif |
634 | 638 | ||
639 | #define TAR_OPT_NOPRESERVE_OWN (1 << (TAR_OPT_AFTER_COMPRESS)) | ||
640 | #define TAR_OPT_NOPRESERVE_PERM (1 << (TAR_OPT_AFTER_COMPRESS + 1)) | ||
641 | #define TAR_OPT_STR_NOPRESERVE "\203\213" | ||
642 | #define TAR_OPT_AFTER_NOPRESERVE TAR_OPT_AFTER_COMPRESS + 2 | ||
643 | |||
635 | static const char tar_options[]="txC:f:Opvk" \ | 644 | static const char tar_options[]="txC:f:Opvk" \ |
636 | TAR_OPT_STR_CREATE \ | 645 | TAR_OPT_STR_CREATE \ |
637 | TAR_OPT_STR_BZIP2 \ | 646 | TAR_OPT_STR_BZIP2 \ |
638 | TAR_OPT_STR_FROM \ | 647 | TAR_OPT_STR_FROM \ |
639 | TAR_OPT_STR_GZIP \ | 648 | TAR_OPT_STR_GZIP \ |
640 | TAR_OPT_STR_COMPRESS; | 649 | TAR_OPT_STR_COMPRESS \ |
650 | TAR_OPT_STR_NOPRESERVE; | ||
641 | 651 | ||
642 | #ifdef CONFIG_FEATURE_TAR_LONG_OPTIONS | 652 | #ifdef CONFIG_FEATURE_TAR_LONG_OPTIONS |
643 | static const struct option tar_long_options[] = { | 653 | static const struct option tar_long_options[] = { |
@@ -649,6 +659,8 @@ static const struct option tar_long_options[] = { | |||
649 | { "same-permissions", 0, NULL, 'p' }, | 659 | { "same-permissions", 0, NULL, 'p' }, |
650 | { "verbose", 0, NULL, 'v' }, | 660 | { "verbose", 0, NULL, 'v' }, |
651 | { "keep-old", 0, NULL, 'k' }, | 661 | { "keep-old", 0, NULL, 'k' }, |
662 | { "no-same-owner", 0, NULL, '\203' }, | ||
663 | { "no-same-permissions",0, NULL, '\213' }, | ||
652 | # ifdef CONFIG_FEATURE_TAR_CREATE | 664 | # ifdef CONFIG_FEATURE_TAR_CREATE |
653 | { "create", 0, NULL, 'c' }, | 665 | { "create", 0, NULL, 'c' }, |
654 | { "dereference", 0, NULL, 'h' }, | 666 | { "dereference", 0, NULL, 'h' }, |
@@ -726,6 +738,11 @@ int tar_main(int argc, char **argv) | |||
726 | if (opt & TAR_OPT_KEEP_OLD) | 738 | if (opt & TAR_OPT_KEEP_OLD) |
727 | tar_handle->flags &= ~ARCHIVE_EXTRACT_UNCONDITIONAL; | 739 | tar_handle->flags &= ~ARCHIVE_EXTRACT_UNCONDITIONAL; |
728 | 740 | ||
741 | if (opt & TAR_OPT_NOPRESERVE_OWN) | ||
742 | tar_handle->flags |= ARCHIVE_NOPRESERVE_OWN; | ||
743 | |||
744 | if (opt & TAR_OPT_NOPRESERVE_PERM) | ||
745 | tar_handle->flags |= ARCHIVE_NOPRESERVE_PERM; | ||
729 | 746 | ||
730 | if (ENABLE_FEATURE_TAR_GZIP && (opt & TAR_OPT_GZIP)) | 747 | if (ENABLE_FEATURE_TAR_GZIP && (opt & TAR_OPT_GZIP)) |
731 | get_header_ptr = get_header_tar_gz; | 748 | get_header_ptr = get_header_tar_gz; |
diff --git a/include/unarchive.h b/include/unarchive.h index b5aacb621..72a803f16 100644 --- a/include/unarchive.h +++ b/include/unarchive.h | |||
@@ -1,11 +1,13 @@ | |||
1 | #ifndef __UNARCHIVE_H__ | 1 | #ifndef __UNARCHIVE_H__ |
2 | #define __UNARCHIVE_H__ | 2 | #define __UNARCHIVE_H__ |
3 | 3 | ||
4 | #define ARCHIVE_PRESERVE_DATE 1 | 4 | #define ARCHIVE_PRESERVE_DATE 1 |
5 | #define ARCHIVE_CREATE_LEADING_DIRS 2 | 5 | #define ARCHIVE_CREATE_LEADING_DIRS 2 |
6 | #define ARCHIVE_EXTRACT_UNCONDITIONAL 4 | 6 | #define ARCHIVE_EXTRACT_UNCONDITIONAL 4 |
7 | #define ARCHIVE_EXTRACT_QUIET 8 | 7 | #define ARCHIVE_EXTRACT_QUIET 8 |
8 | #define ARCHIVE_EXTRACT_NEWER 16 | 8 | #define ARCHIVE_EXTRACT_NEWER 16 |
9 | #define ARCHIVE_NOPRESERVE_OWN 32 | ||
10 | #define ARCHIVE_NOPRESERVE_PERM 64 | ||
9 | 11 | ||
10 | #include <sys/types.h> | 12 | #include <sys/types.h> |
11 | #include <stdio.h> | 13 | #include <stdio.h> |