-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfileartifact.go
69 lines (56 loc) · 1.52 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
60
61
62
63
64
65
66
67
68
69
package baur
import (
"github.com/simplesurance/baur/digest"
"github.com/simplesurance/baur/digest/sha384"
"github.com/simplesurance/baur/fs"
"github.com/simplesurance/baur/upload/scheduler"
)
// FileArtifact is a file build artifact
type FileArtifact struct {
RelPath string
Path string
DestFile string
UploadURL string
uploadJob scheduler.Job
}
// 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() (scheduler.Job, error) {
return f.uploadJob, 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) {
sha := sha384.New()
err := sha.AddFile(f.LocalPath())
if err != nil {
return nil, err
}
return sha.Digest(), err
}
// Size returns the size of the file in bytes
func (f *FileArtifact) Size(_ *BuildOutputBackends) (int64, error) {
return fs.FileSize(f.LocalPath())
}
// Type returns "file"
func (f *FileArtifact) Type() string {
return "file"
}