-
Notifications
You must be signed in to change notification settings - Fork 2
/
link_strategy.go
48 lines (41 loc) · 1.93 KB
/
link_strategy.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
package filetree
const (
// followAncestorLinks deals with link resolution for all constituent paths of a given path (everything except the basename).
// This should not be available to users but may be used internal to the package.
followAncestorLinks LinkResolutionOption = iota
// FollowBasenameLinks deals with link resolution for the basename of a given path (not ancestors).
FollowBasenameLinks
// DoNotFollowDeadBasenameLinks deals with a special case in link resolution: when a basename resolution results in
// a dead link. This option ensures that the last link file that resolved is returned (which exists) instead of
// the non-existing path. This is useful when the caller wants to do custom link resolution (e.g. for container
// images: the link is dead in this layer squash, but does it resolve in a higher layer?).
DoNotFollowDeadBasenameLinks
)
// LinkResolutionOption is a single link resolution rule.
type LinkResolutionOption int
// linkResolutionStrategy describes the full set of possible link resolution rules and their indications (to follow or not).
type linkResolutionStrategy struct {
FollowAncestorLinks bool
FollowBasenameLinks bool
DoNotFollowDeadBasenameLinks bool
}
// newLinkResolutionStrategy creates a new linkResolutionStrategy for the given set of LinkResolutionOptions.
func newLinkResolutionStrategy(options ...LinkResolutionOption) linkResolutionStrategy {
s := linkResolutionStrategy{}
for _, o := range options {
switch o {
case FollowBasenameLinks:
s.FollowBasenameLinks = true
case DoNotFollowDeadBasenameLinks:
s.DoNotFollowDeadBasenameLinks = true
case followAncestorLinks:
s.FollowAncestorLinks = true
}
}
return s
}
// FollowLinks indicates if the current strategy supports following links in one way or another (either in path
// ancestors or basename).
func (s linkResolutionStrategy) FollowLinks() bool {
return s.FollowAncestorLinks || s.FollowBasenameLinks
}