Deleted Added
full compact
write.c (228763) write.c (228776)
1/*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 10 unchanged lines hidden (view full) ---

19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "bsdtar_platform.h"
1/*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 10 unchanged lines hidden (view full) ---

19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "bsdtar_platform.h"
27__FBSDID("$FreeBSD: head/contrib/libarchive/tar/write.c 228763 2011-12-21 11:13:29Z mm $");
27__FBSDID("$FreeBSD: head/contrib/libarchive/tar/write.c 228776 2011-12-21 15:30:49Z mm $");
28
29#ifdef HAVE_SYS_TYPES_H
30#include <sys/types.h>
31#endif
32#ifdef HAVE_SYS_IOCTL_H
33#include <sys/ioctl.h>
34#endif
35#ifdef HAVE_SYS_STAT_H

--- 710 unchanged lines hidden (view full) ---

746 descend = tree_current_is_physical_dir(tree);
747 /* 'P': Don't follow symlinks to files. */
748 archive_read_disk_set_symlink_physical(bsdtar->diskreader);
749 /* 'P': Archive symlinks as symlinks. */
750 st = lst;
751 break;
752 }
753
28
29#ifdef HAVE_SYS_TYPES_H
30#include <sys/types.h>
31#endif
32#ifdef HAVE_SYS_IOCTL_H
33#include <sys/ioctl.h>
34#endif
35#ifdef HAVE_SYS_STAT_H

--- 710 unchanged lines hidden (view full) ---

746 descend = tree_current_is_physical_dir(tree);
747 /* 'P': Don't follow symlinks to files. */
748 archive_read_disk_set_symlink_physical(bsdtar->diskreader);
749 /* 'P': Archive symlinks as symlinks. */
750 st = lst;
751 break;
752 }
753
754 if (bsdtar->option_no_subdirs)
755 descend = 0;
756
754 /*
755 * Are we about to cross to a new filesystem?
756 */
757 if (!dev_recorded) {
758 /* This is the initial file system. */
759 first_dev = lst->st_dev;
760 dev_recorded = 1;
761 } else if (lst->st_dev == first_dev) {
762 /* The starting file system is always acceptable. */
763 } else if (descend == 0) {
764 /* We're not descending, so no need to check. */
765 } else if (bsdtar->option_dont_traverse_mounts) {
757 /*
758 * Are we about to cross to a new filesystem?
759 */
760 if (!dev_recorded) {
761 /* This is the initial file system. */
762 first_dev = lst->st_dev;
763 dev_recorded = 1;
764 } else if (lst->st_dev == first_dev) {
765 /* The starting file system is always acceptable. */
766 } else if (descend == 0) {
767 /* We're not descending, so no need to check. */
768 } else if (bsdtar->option_dont_traverse_mounts) {
766 /* User has asked us not to cross mount points. */
767 descend = 0;
768 } else {
769 /* We're prepared to cross a mount point. */
770
771 /* XXX TODO: check whether this filesystem is
772 * synthetic and/or local. Add a new
773 * --local-only option to skip non-local
774 * filesystems. Skip synthetic filesystems

--- 10 unchanged lines hidden (view full) ---

785 * most of it; other systems will vary.
786 */
787 }
788
789 /*
790 * In -u mode, check that the file is newer than what's
791 * already in the archive; in all modes, obey --newerXXX flags.
792 */
769 descend = 0;
770 } else {
771 /* We're prepared to cross a mount point. */
772
773 /* XXX TODO: check whether this filesystem is
774 * synthetic and/or local. Add a new
775 * --local-only option to skip non-local
776 * filesystems. Skip synthetic filesystems

--- 10 unchanged lines hidden (view full) ---

787 * most of it; other systems will vary.
788 */
789 }
790
791 /*
792 * In -u mode, check that the file is newer than what's
793 * already in the archive; in all modes, obey --newerXXX flags.
794 */
793 if (!new_enough(bsdtar, name, st))
795 if (!new_enough(bsdtar, name, st)) {
796 if (!descend)
797 continue;
798 if (bsdtar->option_interactive &&
799 !yes("add '%s'", name))
800 continue;
801 tree_descend(tree);
794 continue;
802 continue;
803 }
795
796 archive_entry_free(entry);
797 entry = archive_entry_new();
798
799 archive_entry_set_pathname(entry, name);
800 archive_entry_copy_sourcepath(entry,
801 tree_current_access_path(tree));
802

--- 77 unchanged lines hidden (view full) ---

880 * We want this to be fairly late; if some other
881 * check would veto this file, we shouldn't bother
882 * the user with it.
883 */
884 if (bsdtar->option_interactive &&
885 !yes("add '%s'", name))
886 continue;
887
804
805 archive_entry_free(entry);
806 entry = archive_entry_new();
807
808 archive_entry_set_pathname(entry, name);
809 archive_entry_copy_sourcepath(entry,
810 tree_current_access_path(tree));
811

--- 77 unchanged lines hidden (view full) ---

889 * We want this to be fairly late; if some other
890 * check would veto this file, we shouldn't bother
891 * the user with it.
892 */
893 if (bsdtar->option_interactive &&
894 !yes("add '%s'", name))
895 continue;
896
888 /* Note: if user vetoes, we won't descend. */
889 if (descend && !bsdtar->option_no_subdirs)
897 if (descend)
890 tree_descend(tree);
891
892 /*
893 * Rewrite the pathname to be archived. If rewrite
894 * fails, skip the entry.
895 */
896 if (edit_pathname(bsdtar, entry))
897 continue;

--- 33 unchanged lines hidden (view full) ---

931{
932 int fd = -1;
933 int e;
934
935 if (archive_entry_size(entry) > 0) {
936 const char *pathname = archive_entry_sourcepath(entry);
937 fd = open(pathname, O_RDONLY | O_BINARY);
938 if (fd == -1) {
898 tree_descend(tree);
899
900 /*
901 * Rewrite the pathname to be archived. If rewrite
902 * fails, skip the entry.
903 */
904 if (edit_pathname(bsdtar, entry))
905 continue;

--- 33 unchanged lines hidden (view full) ---

939{
940 int fd = -1;
941 int e;
942
943 if (archive_entry_size(entry) > 0) {
944 const char *pathname = archive_entry_sourcepath(entry);
945 fd = open(pathname, O_RDONLY | O_BINARY);
946 if (fd == -1) {
947 bsdtar->return_value = 1;
939 if (!bsdtar->verbose)
940 lafe_warnc(errno,
941 "%s: could not open file", pathname);
942 else
943 fprintf(stderr, ": %s", strerror(errno));
944 return;
945 }
946 }

--- 30 unchanged lines hidden (view full) ---

977 close(fd);
978}
979
980static void
981report_write(struct bsdtar *bsdtar, struct archive *a,
982 struct archive_entry *entry, int64_t progress)
983{
984 uint64_t comp, uncomp;
948 if (!bsdtar->verbose)
949 lafe_warnc(errno,
950 "%s: could not open file", pathname);
951 else
952 fprintf(stderr, ": %s", strerror(errno));
953 return;
954 }
955 }

--- 30 unchanged lines hidden (view full) ---

986 close(fd);
987}
988
989static void
990report_write(struct bsdtar *bsdtar, struct archive *a,
991 struct archive_entry *entry, int64_t progress)
992{
993 uint64_t comp, uncomp;
994 int compression;
995
985 if (bsdtar->verbose)
986 fprintf(stderr, "\n");
987 comp = archive_position_compressed(a);
988 uncomp = archive_position_uncompressed(a);
989 fprintf(stderr, "In: %d files, %s bytes;",
990 archive_file_count(a), tar_i64toa(uncomp));
996 if (bsdtar->verbose)
997 fprintf(stderr, "\n");
998 comp = archive_position_compressed(a);
999 uncomp = archive_position_uncompressed(a);
1000 fprintf(stderr, "In: %d files, %s bytes;",
1001 archive_file_count(a), tar_i64toa(uncomp));
1002 if (comp > uncomp)
1003 compression = 0;
1004 else
1005 compression = (int)((uncomp - comp) * 100 / uncomp);
991 fprintf(stderr,
992 " Out: %s bytes, compression %d%%\n",
1006 fprintf(stderr,
1007 " Out: %s bytes, compression %d%%\n",
993 tar_i64toa(comp), (int)((uncomp - comp) * 100 / uncomp));
1008 tar_i64toa(comp), compression);
994 /* Can't have two calls to tar_i64toa() pending, so split the output. */
995 safe_fprintf(stderr, "Current: %s (%s",
996 archive_entry_pathname(entry),
997 tar_i64toa(progress));
998 fprintf(stderr, "/%s bytes)\n",
999 tar_i64toa(archive_entry_size(entry)));
1000}
1001

--- 24 unchanged lines hidden (view full) ---

1026 lafe_warnc(0,
1027 "%s: Truncated write; file may have grown while being archived.",
1028 archive_entry_pathname(entry));
1029 return (0);
1030 }
1031 progress += bytes_written;
1032 bytes_read = read(fd, bsdtar->buff, FILEDATABUFLEN);
1033 }
1009 /* Can't have two calls to tar_i64toa() pending, so split the output. */
1010 safe_fprintf(stderr, "Current: %s (%s",
1011 archive_entry_pathname(entry),
1012 tar_i64toa(progress));
1013 fprintf(stderr, "/%s bytes)\n",
1014 tar_i64toa(archive_entry_size(entry)));
1015}
1016

--- 24 unchanged lines hidden (view full) ---

1041 lafe_warnc(0,
1042 "%s: Truncated write; file may have grown while being archived.",
1043 archive_entry_pathname(entry));
1044 return (0);
1045 }
1046 progress += bytes_written;
1047 bytes_read = read(fd, bsdtar->buff, FILEDATABUFLEN);
1048 }
1049 if (bytes_read < 0) {
1050 lafe_warnc(errno,
1051 "%s: Read error",
1052 archive_entry_pathname(entry));
1053 bsdtar->return_value = 1;
1054 }
1034 return 0;
1035}
1036
1037/*
1038 * Test if the specified file is new enough to include in the archive.
1039 */
1040static int
1041new_enough(struct bsdtar *bsdtar, const char *path, const struct stat *st)

--- 114 unchanged lines hidden ---
1055 return 0;
1056}
1057
1058/*
1059 * Test if the specified file is new enough to include in the archive.
1060 */
1061static int
1062new_enough(struct bsdtar *bsdtar, const char *path, const struct stat *st)

--- 114 unchanged lines hidden ---