1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-17 15:27:36 +00:00

MfP4: Support for storing birthtime in archive_entry objects.

Submitted by:	Pedro Giffuni
MFC after:	30 days
This commit is contained in:
Tim Kientzle 2008-09-30 03:53:03 +00:00
parent 0c0903b1e1
commit 8b18fa965d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=183481
7 changed files with 73 additions and 0 deletions

View File

@ -460,6 +460,24 @@ archive_entry_atime_is_set(struct archive_entry *entry)
return (entry->ae_set & AE_SET_ATIME);
}
time_t
archive_entry_birthtime(struct archive_entry *entry)
{
return (entry->ae_stat.aest_birthtime);
}
long
archive_entry_birthtime_nsec(struct archive_entry *entry)
{
return (entry->ae_stat.aest_birthtime_nsec);
}
int
archive_entry_birthtime_is_set(struct archive_entry *entry)
{
return (entry->ae_set & AE_SET_BIRTHTIME);
}
time_t
archive_entry_ctime(struct archive_entry *entry)
{
@ -837,6 +855,22 @@ archive_entry_unset_atime(struct archive_entry *entry)
entry->ae_set &= ~AE_SET_ATIME;
}
void
archive_entry_set_birthtime(struct archive_entry *entry, time_t m, long ns)
{
entry->stat_valid = 0;
entry->ae_set |= AE_SET_BIRTHTIME;
entry->ae_stat.aest_birthtime = m;
entry->ae_stat.aest_birthtime_nsec = ns;
}
void
archive_entry_unset_birthtime(struct archive_entry *entry)
{
archive_entry_set_birthtime(entry, 0, 0);
entry->ae_set &= ~AE_SET_BIRTHTIME;
}
void
archive_entry_set_ctime(struct archive_entry *entry, time_t t, long ns)
{

View File

@ -174,6 +174,9 @@ __LA_DECL struct archive_entry *archive_entry_new(void);
__LA_DECL time_t archive_entry_atime(struct archive_entry *);
__LA_DECL long archive_entry_atime_nsec(struct archive_entry *);
__LA_DECL int archive_entry_atime_is_set(struct archive_entry *);
__LA_DECL time_t archive_entry_birthtime(struct archive_entry *);
__LA_DECL long archive_entry_birthtime_nsec(struct archive_entry *);
__LA_DECL int archive_entry_birthtime_is_set(struct archive_entry *);
__LA_DECL time_t archive_entry_ctime(struct archive_entry *);
__LA_DECL long archive_entry_ctime_nsec(struct archive_entry *);
__LA_DECL int archive_entry_ctime_is_set(struct archive_entry *);
@ -224,6 +227,8 @@ __LA_DECL const wchar_t *archive_entry_uname_w(struct archive_entry *);
__LA_DECL void archive_entry_set_atime(struct archive_entry *, time_t, long);
__LA_DECL void archive_entry_unset_atime(struct archive_entry *);
__LA_DECL void archive_entry_set_birthtime(struct archive_entry *, time_t, long);
__LA_DECL void archive_entry_unset_birthtime(struct archive_entry *);
__LA_DECL void archive_entry_set_ctime(struct archive_entry *, time_t, long);
__LA_DECL void archive_entry_unset_ctime(struct archive_entry *);
__LA_DECL void archive_entry_set_dev(struct archive_entry *, dev_t);

View File

@ -47,6 +47,12 @@ archive_entry_copy_stat(struct archive_entry *entry, const struct stat *st)
archive_entry_set_atime(entry, st->st_atime, 0);
archive_entry_set_ctime(entry, st->st_ctime, 0);
archive_entry_set_mtime(entry, st->st_mtime, 0);
#if HAVE_STRUCT_STAT_ST_BIRTHTIME
archive_entry_set_birthtime(entry, st->st_birthtime, 0);
#endif
#endif
#if HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
archive_entry_set_birthtime(entry, st->st_birthtime, st->st_birthtimespec.tv_nsec);
#endif
archive_entry_set_dev(entry, st->st_dev);
archive_entry_set_gid(entry, st->st_gid);

View File

@ -112,6 +112,8 @@ struct archive_entry {
uint32_t aest_ctime_nsec;
int64_t aest_mtime;
uint32_t aest_mtime_nsec;
int64_t aest_birthtime;
uint32_t aest_birthtime_nsec;
gid_t aest_gid;
ino_t aest_ino;
mode_t aest_mode;
@ -142,6 +144,7 @@ struct archive_entry {
#define AE_SET_ATIME 4
#define AE_SET_CTIME 8
#define AE_SET_MTIME 16
#define AE_SET_BIRTHTIME 32
#define AE_SET_SIZE 64
/*

View File

@ -64,6 +64,9 @@ archive_entry_stat(struct archive_entry *entry)
* the appropriate conversions get invoked.
*/
st->st_atime = archive_entry_atime(entry);
#if HAVE_STRUCT_STAT_ST_BIRTHTIME
st->st_birthtime = archive_entry_birthtime(entry);
#endif
st->st_ctime = archive_entry_ctime(entry);
st->st_mtime = archive_entry_mtime(entry);
st->st_dev = archive_entry_dev(entry);
@ -88,6 +91,9 @@ archive_entry_stat(struct archive_entry *entry)
st->st_ctim.tv_nsec = archive_entry_ctime_nsec(entry);
st->st_mtim.tv_nsec = archive_entry_mtime_nsec(entry);
#endif
#if HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
st->st_birthtimespec.tv_nsec = archive_entry_birthtime_nsec(entry);
#endif
/*
* TODO: On Linux, store 32 or 64 here depending on whether

View File

@ -89,6 +89,8 @@
#define HAVE_STRING_H 1
#define HAVE_STRRCHR 1
#define HAVE_STRUCT_STAT_ST_BLKSIZE 1
#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1
#define HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1
#define HAVE_STRUCT_STAT_ST_FLAGS 1
#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1
#define HAVE_SYS_ACL_H 1

View File

@ -79,6 +79,15 @@ DEFINE_TEST(test_entry)
assertEqualInt(archive_entry_atime_nsec(e), 0);
assert(!archive_entry_atime_is_set(e));
/* birthtime */
archive_entry_set_birthtime(e, 17579, 24990);
assertEqualInt(archive_entry_birthtime(e), 17579);
assertEqualInt(archive_entry_birthtime_nsec(e), 24990);
archive_entry_unset_birthtime(e);
assertEqualInt(archive_entry_birthtime(e), 0);
assertEqualInt(archive_entry_birthtime_nsec(e), 0);
assert(!archive_entry_birthtime_is_set(e));
/* ctime */
archive_entry_set_ctime(e, 13580, 24681);
assertEqualInt(archive_entry_ctime(e), 13580);
@ -312,6 +321,7 @@ DEFINE_TEST(test_entry)
/* Set values in 'e' */
archive_entry_clear(e);
archive_entry_set_atime(e, 13579, 24680);
archive_entry_set_birthtime(e, 13779, 24990);
archive_entry_set_ctime(e, 13580, 24681);
#if ARCHIVE_VERSION_NUMBER >= 1009000
archive_entry_set_dev(e, 235);
@ -348,6 +358,8 @@ DEFINE_TEST(test_entry)
/* Clone should have same contents. */
assertEqualInt(archive_entry_atime(e2), 13579);
assertEqualInt(archive_entry_atime_nsec(e2), 24680);
assertEqualInt(archive_entry_birthtime(e2), 13779);
assertEqualInt(archive_entry_birthtime_nsec(e2), 24990);
assertEqualInt(archive_entry_ctime(e2), 13580);
assertEqualInt(archive_entry_ctime_nsec(e2), 24681);
#if ARCHIVE_VERSION_NUMBER >= 1009000
@ -435,6 +447,7 @@ DEFINE_TEST(test_entry)
/* Change the original */
archive_entry_set_atime(e, 13580, 24690);
archive_entry_set_birthtime(e, 13980, 24999);
archive_entry_set_ctime(e, 13590, 24691);
#if ARCHIVE_VERSION_NUMBER >= 1009000
archive_entry_set_dev(e, 245);
@ -468,6 +481,8 @@ DEFINE_TEST(test_entry)
/* Clone should still have same contents. */
assertEqualInt(archive_entry_atime(e2), 13579);
assertEqualInt(archive_entry_atime_nsec(e2), 24680);
assertEqualInt(archive_entry_birthtime(e2), 13779);
assertEqualInt(archive_entry_birthtime_nsec(e2), 24990);
assertEqualInt(archive_entry_ctime(e2), 13580);
assertEqualInt(archive_entry_ctime_nsec(e2), 24681);
#if ARCHIVE_VERSION_NUMBER >= 1009000
@ -561,6 +576,8 @@ DEFINE_TEST(test_entry)
archive_entry_clear(e);
assertEqualInt(archive_entry_atime(e), 0);
assertEqualInt(archive_entry_atime_nsec(e), 0);
assertEqualInt(archive_entry_birthtime(e), 0);
assertEqualInt(archive_entry_birthtime_nsec(e), 0);
assertEqualInt(archive_entry_ctime(e), 0);
assertEqualInt(archive_entry_ctime_nsec(e), 0);
assertEqualInt(archive_entry_dev(e), 0);