From 3a2a859dd4bf151712758da09adfe88aa5b54347 Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Wed, 1 Jun 2005 15:44:23 +0000 Subject: A minor refinement to "pax" output: Remove suid/sgid/sticky bits from mode before using mode for extended attributes entry, copy mtime/atime/ctime to extended attributes entry so it's a little more clear that it corresponds to the like-named regular entry. MFC after: 14 days --- lib/libarchive/archive_entry.c | 14 ++++++++++++++ lib/libarchive/archive_entry.h | 2 ++ lib/libarchive/archive_write_set_format_pax.c | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/lib/libarchive/archive_entry.c b/lib/libarchive/archive_entry.c index b4b743530fb4..974137763b09 100644 --- a/lib/libarchive/archive_entry.c +++ b/lib/libarchive/archive_entry.c @@ -568,6 +568,20 @@ archive_entry_copy_hardlink_w(struct archive_entry *entry, const wchar_t *target aes_copy_wcs(&entry->ae_hardlink, target); } +void +archive_entry_set_atime(struct archive_entry *entry, time_t t, long ns) +{ + entry->ae_stat.st_atime = t; + ARCHIVE_STAT_SET_ATIME_NANOS(&entry->ae_stat, ns); +} + +void +archive_entry_set_ctime(struct archive_entry *entry, time_t t, long ns) +{ + entry->ae_stat.st_ctime = t; + ARCHIVE_STAT_SET_CTIME_NANOS(&entry->ae_stat, ns); +} + /* Set symlink if symlink is already set, else set hardlink. */ void archive_entry_set_link(struct archive_entry *entry, const char *target) diff --git a/lib/libarchive/archive_entry.h b/lib/libarchive/archive_entry.h index 2f67c8afa0e0..cba416dbe2fd 100644 --- a/lib/libarchive/archive_entry.h +++ b/lib/libarchive/archive_entry.h @@ -96,6 +96,8 @@ const char *archive_entry_uname(struct archive_entry *); */ void archive_entry_copy_stat(struct archive_entry *, const struct stat *); +void archive_entry_set_atime(struct archive_entry *, time_t, long); +void archive_entry_set_ctime(struct archive_entry *, time_t, long); void archive_entry_set_fflags(struct archive_entry *, unsigned long set, unsigned long clear); /* Returns pointer to start of first invalid token, or NULL if none. */ diff --git a/lib/libarchive/archive_write_set_format_pax.c b/lib/libarchive/archive_write_set_format_pax.c index 2309909e6bc9..479cca6206d5 100644 --- a/lib/libarchive/archive_write_set_format_pax.c +++ b/lib/libarchive/archive_write_set_format_pax.c @@ -643,19 +643,41 @@ archive_write_pax_header(struct archive *a, archive_entry_set_pathname(pax_attr_entry, build_pax_attribute_name(pax_entry_name, p)); st.st_size = archive_strlen(&(pax->pax_header)); + /* Copy uid/gid (but clip to ustar limits). */ st.st_uid = st_main->st_uid; if (st.st_uid >= 1 << 18) st.st_uid = (1 << 18) - 1; st.st_gid = st_main->st_gid; if (st.st_gid >= 1 << 18) st.st_gid = (1 << 18) - 1; + /* Copy mode over (but not setuid/setgid bits) */ st.st_mode = st_main->st_mode; +#ifdef S_ISUID + st.st_mode &= ~S_ISUID; +#endif +#ifdef S_ISGID + st.st_mode &= ~S_ISGID; +#endif +#ifdef S_ISVTX + st.st_mode &= ~S_ISVTX; +#endif archive_entry_copy_stat(pax_attr_entry, &st); + /* Copy uname/gname. */ archive_entry_set_uname(pax_attr_entry, archive_entry_uname(entry_main)); archive_entry_set_gname(pax_attr_entry, archive_entry_gname(entry_main)); + /* Copy timestamps. */ + archive_entry_set_mtime(pax_attr_entry, + archive_entry_mtime(entry_main), + archive_entry_mtime_nsec(entry_main)); + archive_entry_set_atime(pax_attr_entry, + archive_entry_atime(entry_main), + archive_entry_atime_nsec(entry_main)); + archive_entry_set_ctime(pax_attr_entry, + archive_entry_ctime(entry_main), + archive_entry_ctime_nsec(entry_main)); ret = __archive_write_format_header_ustar(a, paxbuff, pax_attr_entry, 'x', 1); -- cgit v1.2.3