Skip to content

archive: windows: chtimes(): remove redundant conversion#7491

Merged
kzys merged 1 commit intocontainerd:mainfrom
thaJeztah:chtimes_redundancy
Oct 7, 2022
Merged

archive: windows: chtimes(): remove redundant conversion#7491
kzys merged 1 commit intocontainerd:mainfrom
thaJeztah:chtimes_redundancy

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

It looks like this function was converting the time (windows.NsecToTimespec()), only to convert it back (windows.TimespecToNsec()). This became clear when moving the lines together:

ctimespec := windows.NsecToTimespec(ctime.UnixNano())
c := windows.NsecToFiletime(windows.TimespecToNsec(ctimespec))

And looking at the Golang code, it looks like they're indeed the exact reverse:

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
    ts.Sec = nsec / 1e9
    ts.Nsec = nsec % 1e9
    return
}

While modifying this code, also renaming the e variable to a more common err.

It looks like this function was converting the time (`windows.NsecToTimespec()`),
only to convert it back (`windows.TimespecToNsec()`). This became clear when
moving the lines together:

```go
ctimespec := windows.NsecToTimespec(ctime.UnixNano())
c := windows.NsecToFiletime(windows.TimespecToNsec(ctimespec))
```

And looking at the Golang code, it looks like they're indeed the exact reverse:

```go
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
    ts.Sec = nsec / 1e9
    ts.Nsec = nsec % 1e9
    return
}
```

While modifying this code, also renaming the `e` variable to a more common `err`.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Copy link
Copy Markdown
Member

@kevpar kevpar left a comment

Choose a reason for hiding this comment

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

LGTM pending CI

@kzys kzys merged commit 4a0ddfa into containerd:main Oct 7, 2022
@thaJeztah thaJeztah deleted the chtimes_redundancy branch October 7, 2022 23:17
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