1
0
Fork 0
mirror of https://github.com/Luzifer/cloudbox.git synced 2024-11-08 22:20:09 +00:00
cloudbox/providers/file.go

55 lines
1 KiB
Go
Raw Normal View History

2019-06-16 00:05:06 +00:00
package providers
import (
2019-06-16 16:53:30 +00:00
"hash"
2019-06-16 00:05:06 +00:00
"io"
"time"
"github.com/pkg/errors"
)
var ErrFileNotFound = errors.New("File not found")
type File interface {
Info() FileInfo
2019-06-16 16:53:30 +00:00
Checksum(hash.Hash) (string, error)
2019-06-16 00:05:06 +00:00
Content() (io.ReadCloser, error)
}
type FileInfo struct {
RelativeName string
LastModified time.Time
Checksum string // Expected to be present on CapAutoChecksum
Size uint64
}
2019-06-16 16:53:30 +00:00
func (f *FileInfo) Equal(other *FileInfo) bool {
if f == nil && other == nil {
// Both are not present: No change
return true
}
if (f != nil && other == nil) || (f == nil && other != nil) {
// One is not present, the other is: Change
return false
}
if (f.Checksum != "" || other.Checksum != "") && f.Checksum != other.Checksum {
// Checksum is present in one, doesn't match: Change
return false
}
if f.Size != other.Size {
// No checksums present, size differs: Change
return false
}
if !f.LastModified.Equal(other.LastModified) {
// LastModified date differs: Change
return false
}
// No changes detected yet: No change
return true
}