1
0

structs.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at http://mozilla.org/MPL/2.0/.
  6. //go:generate go run ../../script/protofmt.go structs.proto
  7. //go:generate protoc -I ../../../../../ -I ../../vendor/ -I ../../vendor/github.com/gogo/protobuf/protobuf -I . --gogofast_out=. structs.proto
  8. package db
  9. import (
  10. "fmt"
  11. "time"
  12. "github.com/syncthing/syncthing/lib/protocol"
  13. )
  14. func (f FileInfoTruncated) String() string {
  15. return fmt.Sprintf("File{Name:%q, Permissions:0%o, Modified:%v, Version:%v, Length:%d, Deleted:%v, Invalid:%v, NoPermissions:%v}",
  16. f.Name, f.Permissions, f.ModTime(), f.Version, f.Size, f.Deleted, f.Invalid, f.NoPermissions)
  17. }
  18. func (f FileInfoTruncated) IsDeleted() bool {
  19. return f.Deleted
  20. }
  21. func (f FileInfoTruncated) IsInvalid() bool {
  22. return f.Invalid
  23. }
  24. func (f FileInfoTruncated) IsDirectory() bool {
  25. return f.Type == protocol.FileInfoTypeDirectory
  26. }
  27. func (f FileInfoTruncated) IsSymlink() bool {
  28. switch f.Type {
  29. case protocol.FileInfoTypeSymlink, protocol.FileInfoTypeDeprecatedSymlinkDirectory, protocol.FileInfoTypeDeprecatedSymlinkFile:
  30. return true
  31. default:
  32. return false
  33. }
  34. }
  35. func (f FileInfoTruncated) HasPermissionBits() bool {
  36. return !f.NoPermissions
  37. }
  38. func (f FileInfoTruncated) FileSize() int64 {
  39. if f.Deleted {
  40. return 0
  41. }
  42. if f.IsDirectory() || f.IsSymlink() {
  43. return protocol.SyntheticDirectorySize
  44. }
  45. return f.Size
  46. }
  47. func (f FileInfoTruncated) FileName() string {
  48. return f.Name
  49. }
  50. func (f FileInfoTruncated) ModTime() time.Time {
  51. return time.Unix(f.ModifiedS, int64(f.ModifiedNs))
  52. }