/
main.go
96 lines (84 loc) · 3.06 KB
/
main.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// Copyright © 2016-2017 Ikey Doherty <ikey@solus-project.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package source
import (
"os"
"strings"
)
const (
// SourceDir is where we store all tarballs
SourceDir = "/var/lib/solbuild/sources"
// SourceStagingDir is where we initially fetch downloads
SourceStagingDir = "/var/lib/solbuild/sources/staging"
)
// A BindConfiguration is used by a source as a way to express bind
// mounts required for a given source.
//
// In solbuild, *all* sources are bind mounted to the target cache,
// regardless of their type.
//
// Special care is taken to ensure that they will be bound in a way
// compatible with the target system.
type BindConfiguration struct {
BindSource string // The localy cached source
BindTarget string // Target within the filesystem
}
// A Source is a general representation of source listed in a package
// spec file.
//
// Source's may be of multiple types, but all are abstracted and dealt
// with by the interfaces.
type Source interface {
// IsFetched is called during the early build process to determine
// whether this source is available for use.
IsFetched() bool
// Fetch will attempt to fetch the this source locally and cache it.
Fetch() error
// GetBindConfiguration should return a valid configuration specifying
// the origin on our local filesystem, and the target within the container.
// The target should include the full source dir.
GetBindConfiguration(rootfs string) BindConfiguration
// GetIdentifier will return the appropriate representation for a given
// source URL.
GetIdentifier() string
}
// New will return a new source for the specified URL.
//
// Validator is the value by which the source will be validated, depending
// on implementation. For example, the SimpleSource backend will expect a
// hashsum: sha256sum for package.yml, and sha1sum for legacy.
//
// The legacy argument will determine whether special care should be taken
// for legacy packages (i.e. sha1sum vs sha256sum).
//
// In all cases, New will fallback to the SimpleSource implementation
func New(uri, validator string, legacy bool) (Source, error) {
if legacy {
return NewSimple(uri, validator, legacy)
}
// Handle git sources. Not supported in legacy format, ypkg only.
if strings.HasPrefix(uri, "git|") {
return NewGit(uri[len("git|"):], validator)
}
return NewSimple(uri, validator, legacy)
}
// PathExists is a helper function to determine the existence of a file path
func PathExists(path string) bool {
if st, err := os.Stat(path); err == nil && st != nil {
return true
}
return false
}