github.com/advanderveer/restic@v0.8.1-0.20171209104529-42a8c19aaea6/internal/restic/file.go (about) 1 package restic 2 3 import ( 4 "fmt" 5 6 "github.com/restic/restic/internal/errors" 7 ) 8 9 // FileType is the type of a file in the backend. 10 type FileType string 11 12 // These are the different data types a backend can store. 13 const ( 14 DataFile FileType = "data" 15 KeyFile = "key" 16 LockFile = "lock" 17 SnapshotFile = "snapshot" 18 IndexFile = "index" 19 ConfigFile = "config" 20 ) 21 22 // Handle is used to store and access data in a backend. 23 type Handle struct { 24 Type FileType 25 Name string 26 } 27 28 func (h Handle) String() string { 29 name := h.Name 30 if len(name) > 10 { 31 name = name[:10] 32 } 33 return fmt.Sprintf("<%s/%s>", h.Type, name) 34 } 35 36 // Valid returns an error if h is not valid. 37 func (h Handle) Valid() error { 38 if h.Type == "" { 39 return errors.New("type is empty") 40 } 41 42 switch h.Type { 43 case DataFile: 44 case KeyFile: 45 case LockFile: 46 case SnapshotFile: 47 case IndexFile: 48 case ConfigFile: 49 default: 50 return errors.Errorf("invalid Type %q", h.Type) 51 } 52 53 if h.Type == ConfigFile { 54 return nil 55 } 56 57 if h.Name == "" { 58 return errors.New("invalid Name") 59 } 60 61 return nil 62 }