forked from simplesurance/baur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileartifact.go
59 lines (49 loc) · 1.37 KB
/
fileartifact.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package baur
import (
"github.com/simplesurance/baur/digest"
"github.com/simplesurance/baur/digest/sha384"
"github.com/simplesurance/baur/fs"
"github.com/simplesurance/baur/upload"
)
// FileArtifact is a file build artifact
type FileArtifact struct {
RelPath string
Path string
DestFile string
UploadURL string
}
// Exists returns true if the artifact exist
func (f *FileArtifact) Exists() bool {
return fs.FileExists(f.Path)
}
// String returns the String representation
func (f *FileArtifact) String() string {
return f.RelPath
}
// UploadJob returns a upload.DockerJob for the artifact
func (f *FileArtifact) UploadJob() (upload.Job, error) {
return &upload.S3Job{
DestURL: f.UploadURL,
FilePath: f.Path,
}, nil
}
// LocalPath returns the local path to the artifact
func (f *FileArtifact) LocalPath() string {
return f.Path
}
// Name returns the path to the artifact relatively to application dir
func (f *FileArtifact) Name() string {
return f.RelPath
}
// UploadDestination returns the upload destination
func (f *FileArtifact) UploadDestination() string {
return f.UploadURL
}
// Digest returns the file digest
func (f *FileArtifact) Digest() (*digest.Digest, error) {
return sha384.File(f.LocalPath())
}
// Size returns the size of the file in bytes
func (f *FileArtifact) Size(_ *BuildOutputBackends) (int64, error) {
return fs.FileSize(f.LocalPath())
}