This repository has been archived by the owner on Feb 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 887
/
main.go
88 lines (76 loc) · 2.27 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
// Copyright 2015 The rkt Authors
//
// 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 main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/coreos/rkt/tools/common"
"github.com/coreos/rkt/tools/common/filelist"
)
type mkPair struct {
name string
data *[]string
}
func main() {
filename, mapTo := getValidArgs()
list := getListing(filename)
pairs := getPairs(list)
for _, pair := range pairs {
toClean := common.MapFilesToDirectories(*pair.data, mapTo)
fmt.Printf("%s += %s\n", pair.name, strings.Join(toClean, " "))
}
}
func getValidArgs() (string, []string) {
filename := ""
var mapTo []string
mapToWrapper := common.StringSliceWrapper{
Slice: &mapTo,
}
flag.StringVar(&filename, "filelist", "", "Name of the source (path to the directory or to the filelist")
flag.Var(&mapToWrapper, "map-to", "Map contents of traversed source to this directory, can be used multiple times")
flag.Parse()
if filename == "" {
common.Die("No --filelist parameter passed")
}
if len(mapTo) < 1 {
common.Die("No --map-to parameter passed, at least one is required")
os.Exit(1)
}
filename = common.MustAbs(filename)
for i := 0; i < len(mapTo); i++ {
mapTo[i] = common.MustAbs(mapTo[i])
}
return filename, mapTo
}
func getListing(filename string) *filelist.Lists {
fl, err := os.Open(filename)
if err != nil {
common.Die("Failed to open filelist %q: %v", filename, err)
}
defer fl.Close()
list := &filelist.Lists{}
if err := list.ParseFilelist(fl); err != nil {
common.Die("Error during getting listing from filelist %q: %v\n", filename, err)
}
return list
}
func getPairs(list *filelist.Lists) []mkPair {
return []mkPair{
{name: "CLEAN_FILES", data: &list.Files},
{name: "CLEAN_SYMLINKS", data: &list.Symlinks},
{name: "CLEAN_DIRS", data: &list.Dirs},
}
}