MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / Init

Method Init

drivers/alias/driver.go:41–97  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

39}
40
41func (d *Alias) Init(ctx context.Context) error {
42 paths := strings.Split(d.Paths, "\n")
43 d.rootOrder = make([]string, 0, len(paths))
44 d.pathMap = make(map[string][]string)
45 for _, path := range paths {
46 path = strings.TrimSpace(path)
47 if path == "" {
48 continue
49 }
50 k, v := getPair(path)
51 temp, ok := d.pathMap[k]
52 if !ok {
53 d.rootOrder = append(d.rootOrder, k)
54 }
55 d.pathMap[k] = append(temp, v)
56 }
57
58 switch len(d.rootOrder) {
59 case 0:
60 return errors.New("paths is required")
61 case 1:
62 paths := d.pathMap[d.rootOrder[0]]
63 roots := make(BalancedObjs, 0, len(paths))
64 roots = append(roots, &model.Object{
65 Name: "root",
66 Path: paths[0],
67 IsFolder: true,
68 Modified: d.Modified,
69 Mask: model.Locked,
70 })
71 for _, path := range paths[1:] {
72 roots = append(roots, &model.Object{
73 Path: path,
74 })
75 }
76 d.root = roots
77 default:
78 d.root = &model.Object{
79 Name: "root",
80 Path: "/",
81 IsFolder: true,
82 Modified: d.Modified,
83 Mask: model.ReadOnly,
84 }
85 }
86
87 if !utils.SliceContains(ValidReadConflictPolicy, d.ReadConflictPolicy) {
88 d.ReadConflictPolicy = FirstRWP
89 }
90 if !utils.SliceContains(ValidWriteConflictPolicy, d.WriteConflictPolicy) {
91 d.WriteConflictPolicy = DisabledWP
92 }
93 if !utils.SliceContains(ValidPutConflictPolicy, d.PutConflictPolicy) {
94 d.PutConflictPolicy = DisabledWP
95 }
96 return nil
97}
98

Callers

nothing calls this directly

Calls 2

SliceContainsFunction · 0.92
getPairFunction · 0.70

Tested by

no test coverage detected