Skip to content

Commit

Permalink
MacOS: use 1s resolution when comparing timestamps
Browse files Browse the repository at this point in the history
1s is what the MacOS SMB client supports.

See

  3e1f62b
  Compare timestamps with 100ns resolution instead of 1ns

for what problem this solves.

Fixes #21
  • Loading branch information
rfjakob committed Apr 16, 2023
1 parent a6dac39 commit b3e75ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
8 changes: 5 additions & 3 deletions README.changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ Changelog
*Short changelog - for all the details look at the git log.*

vNEXT, in progress
* Use 100ns resultion when comparing timestamps instead of 1ns
to match SMB restrictions
([#21](https://github.com/rfjakob/cshatag/issues/21),
* Linux: use 100ns resolution when comparing timestamps instead of 1ns
to match SMB protocol restrictions
([#21](https://github.com/rfjakob/cshatag/issues/21)
[commit](https://github.com/rfjakob/cshatag/commit/3e1f62b38b493b2be75437c208ae7b1d6a90c8e8))
* MacOS: use 1s resolution when comparing timestamps to match
MacOS SMB client restrictions ([#21](https://github.com/rfjakob/cshatag/issues/21))

v2.1.0, 2022-10-22
* Add `-dry-run` [#22](https://github.com/rfjakob/cshatag/issues/22)
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ Changelog
*Short changelog - for all the details look at the git log.*

vNEXT, in progress
* Use 100ns resultion when comparing timestamps instead of 1ns
to match SMB restrictions
([#21](https://github.com/rfjakob/cshatag/issues/21),
* Linux: use 100ns resolution when comparing timestamps instead of 1ns
to match SMB protocol restrictions
([#21](https://github.com/rfjakob/cshatag/issues/21)
[commit](https://github.com/rfjakob/cshatag/commit/3e1f62b38b493b2be75437c208ae7b1d6a90c8e8))
* MacOS: use 1s resolution when comparing timestamps to match
MacOS SMB client restrictions ([#21](https://github.com/rfjakob/cshatag/issues/21))

v2.1.0, 2022-10-22
* Add `-dry-run` [#22](https://github.com/rfjakob/cshatag/issues/22)
Expand Down
14 changes: 10 additions & 4 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"os"
"runtime"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -33,12 +34,17 @@ func (ts *fileTimestamp) prettyPrint() string {
return fmt.Sprintf("%010d.%09d", ts.s, ts.ns)
}

// equal100ns compares ts and ts2 with 100ns resolution.
// Why 100ns? That's what SMB supports.
func (ts *fileTimestamp) equal100ns(ts2 *fileTimestamp) bool {
// equalTruncatedTimestamp compares ts and ts2 with 100ns resolution (Linux) or 1s (MacOS).
// Why 100ns? That's what Samba and the Linux SMB client supports.
// Why 1s? That's what the MacOS SMB client supports.
func (ts *fileTimestamp) equalTruncatedTimestamp(ts2 *fileTimestamp) bool {
if ts.s != ts2.s {
return false
}
// We only look at integer seconds on MacOS, so we are done here.
if runtime.GOOS == "darwin" {
return true
}
if ts.ns/100 != ts2.ns/100 {
return false
}
Expand Down Expand Up @@ -156,7 +162,7 @@ func checkFile(fn string) {
return
}

if stored.ts.equal100ns(&actual.ts) {
if stored.ts.equalTruncatedTimestamp(&actual.ts) {
if bytes.Equal(stored.sha256, actual.sha256) {
if !args.q {
fmt.Printf("<ok> %s\n", fn)
Expand Down

0 comments on commit b3e75ef

Please sign in to comment.