structs.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 --proto_path=../../../../../:../../../../gogo/protobuf/protobuf:. --gogofast_out=. structs.proto
  8. package db
  9. import (
  10. "fmt"
  11. "github.com/syncthing/syncthing/lib/protocol"
  12. )
  13. func (f FileInfoTruncated) String() string {
  14. return fmt.Sprintf("File{Name:%q, Permissions:0%o, Modified:%d, Version:%v, Length:%d, Deleted:%v, Invalid:%v, NoPermissions:%v}",
  15. f.Name, f.Permissions, f.Modified, f.Version, f.Size, f.Deleted, f.Invalid, f.NoPermissions)
  16. }
  17. func (f FileInfoTruncated) IsDeleted() bool {
  18. return f.Deleted
  19. }
  20. func (f FileInfoTruncated) IsInvalid() bool {
  21. return f.Invalid
  22. }
  23. func (f FileInfoTruncated) IsDirectory() bool {
  24. return f.Type == protocol.FileInfoTypeDirectory
  25. }
  26. func (f FileInfoTruncated) IsSymlink() bool {
  27. switch f.Type {
  28. case protocol.FileInfoTypeSymlinkDirectory, protocol.FileInfoTypeSymlinkFile, protocol.FileInfoTypeSymlinkUnknown:
  29. return true
  30. default:
  31. return false
  32. }
  33. }
  34. func (f FileInfoTruncated) HasPermissionBits() bool {
  35. return !f.NoPermissions
  36. }
  37. func (f FileInfoTruncated) FileSize() int64 {
  38. if f.IsDirectory() || f.IsDeleted() {
  39. return 128
  40. }
  41. return f.Size
  42. }
  43. func (f FileInfoTruncated) FileName() string {
  44. return f.Name
  45. }