Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proto: support timestamps #88

Closed
wants to merge 1 commit into from
Closed

Conversation

AkihiroSuda
Copy link
Member

Fix #16 #30

Applier is not implemented yet

@stevvooe @dmcgowan @aaronlehmann @tonistiigi

Signed-off-by: Akihiro Suda [email protected]

Signed-off-by: Akihiro Suda <[email protected]>
@@ -65,6 +67,13 @@ message Resource {
// Ads stores one or more alternate data streams for the target resource.
repeated ADSEntry ads = 13;

// Timestamps.
// btime (birthtime) is available on Darwin, FreeBSD, NetBSD, and Windows.
// When btime is unknown, it SHOULD be set to zero.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not omit the field instead of setting it to zero? I believe these fields are nullable.

ATime() time.Time
MTime() time.Time
CTime() time.Time
BTime() time.Time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to use these abbreviated forms - they're pretty widely used. But it would be useful to have a comment explaining what each one means.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it might be okay to follow the times library and just have AccessTime, ModTime and ChangeTime.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document these. Please change to the expanded versions to match golang os package.

@@ -108,6 +116,22 @@ func Merge(fs ...Resource) (Resource, error) {
return nil, fmt.Errorf("gid does not match: %v != %v", f.GID(), prototype.GID())
}

if f.ATime() != prototype.ATime() {
return nil, fmt.Errorf("atime does not match: %v != %v", f.ATime(), prototype.ATime())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little worried this will be racy. If a hardlinked file is accessed in between the Stats, atime wouldn't match. The existing checks for things like mode and UID/GID are much less likely to change in the narrow window between two Stats.

Should we avoid considering atime when merging hardlinks?

@@ -503,13 +560,25 @@ func toProto(resource Resource) *pb.Resource {
return b
}

func timestampFromProto(ts *tspb.Timestamp) time.Time {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's return time.Time{} when ts == nil. This will clearly distinguish missing timestamps, for example from old manifests that don't implement timestamping, or ones generated on OSs that don't support every field. Otherwise we would return the unix epoch here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use the protobuf helper function here.

@@ -190,6 +194,26 @@ func (c *context) Resource(p string, fi os.FileInfo) (Resource, error) {
return nil, ErrNotFound
}

func (c *context) verifyTimestamps(resource, target Resource) error {
unixZero := func(t time.Time) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with t.IsZero()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More interestingly, why do we care about unix time?

base.btime = ts.BirthTime()
} else {
// Note: time.Time{} stands for 0001-01-01 00:00:00 UTC
base.btime = time.Unix(0, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very worried about the redefinition of the zero time. This should really be time.Time{}.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that get serialized correctly?

@AkihiroSuda
Copy link
Member Author

AkihiroSuda commented Nov 21, 2017

I'm not sure whether we should use 0001-epoch timestamp. i.e. time.Time{} rather than time.Unix(0, 0)

According to Wikipedia, most filesystems except FAT support Unix(1970)-epoch zero but not 0001-epoch zero:

Filesystem From To
Ext4 December 14, 1901 May 10, 2446
Ext3 December 14, 1901 January 18, 2038
Ext2 December 14, 1901 January 18, 2038
XFS December 14, 1901 January 18, 2038
HFS+ January 1, 1904 February 6, 2040
NTFS January 1, 1601 May 28, 60056
FAT January 1, 1980 December 31, 2099 (December 31, 2107)

So my initial opinion is to consistently use 1970 epoch, but no strong opinion.

@AkihiroSuda
Copy link
Member Author

Any thought for timestamp epoch?

@stevvooe
Copy link
Member

stevvooe commented Feb 2, 2018

Any thought for timestamp epoch?

Use proper time types, ie time.Time{}.

// Timestamps.
// btime (birthtime) is available on Darwin, FreeBSD, NetBSD, and Windows.
// When btime is unknown, it SHOULD be set to zero.
google.protobuf.Timestamp atime = 14;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to document the fields.

@AkihiroSuda
Copy link
Member Author

Use proper time types, ie time.Time{}.

How to apply when it is before 19011214 (especially zero)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants