2
2
mirror of https://github.com/octoleo/restic.git synced 2024-05-28 06:30:53 +00:00
restic/internal/restic/file.go

63 lines
1.1 KiB
Go
Raw Normal View History

package restic
import (
"fmt"
2017-07-23 12:21:03 +00:00
"github.com/restic/restic/internal/errors"
)
2016-08-31 18:29:54 +00:00
// FileType is the type of a file in the backend.
type FileType string
// These are the different data types a backend can store.
const (
DataFile FileType = "data"
KeyFile = "key"
LockFile = "lock"
SnapshotFile = "snapshot"
IndexFile = "index"
ConfigFile = "config"
)
// Handle is used to store and access data in a backend.
type Handle struct {
2016-09-01 19:19:30 +00:00
Type FileType
Name string
}
func (h Handle) String() string {
name := h.Name
if len(name) > 10 {
name = name[:10]
}
2016-09-01 19:19:30 +00:00
return fmt.Sprintf("<%s/%s>", h.Type, name)
}
// Valid returns an error if h is not valid.
func (h Handle) Valid() error {
2016-09-01 19:19:30 +00:00
if h.Type == "" {
return errors.New("type is empty")
}
2016-09-01 19:19:30 +00:00
switch h.Type {
case DataFile:
case KeyFile:
case LockFile:
case SnapshotFile:
case IndexFile:
case ConfigFile:
default:
2016-09-01 19:19:30 +00:00
return errors.Errorf("invalid Type %q", h.Type)
}
2016-09-01 19:19:30 +00:00
if h.Type == ConfigFile {
return nil
}
if h.Name == "" {
return errors.New("invalid Name")
}
return nil
}