time.go 1012 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. Copyright The containerd Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package fs
  14. import "time"
  15. // Gnu tar and the go tar writer don't have sub-second mtime
  16. // precision, which is problematic when we apply changes via tar
  17. // files, we handle this by comparing for exact times, *or* same
  18. // second count and either a or b having exactly 0 nanoseconds
  19. func sameFsTime(a, b time.Time) bool {
  20. return a == b ||
  21. (a.Unix() == b.Unix() &&
  22. (a.Nanosecond() == 0 || b.Nanosecond() == 0))
  23. }