structs.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 https://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. }
  53. func (f FileInfoTruncated) SequenceNo() int64 {
  54. return f.Sequence
  55. }
  56. func (f FileInfoTruncated) ConvertToInvalidFileInfo(invalidatedBy protocol.ShortID) protocol.FileInfo {
  57. return protocol.FileInfo{
  58. Name: f.Name,
  59. Type: f.Type,
  60. ModifiedS: f.ModifiedS,
  61. ModifiedNs: f.ModifiedNs,
  62. ModifiedBy: invalidatedBy,
  63. Invalid: true,
  64. Version: f.Version,
  65. }
  66. }