LoadDir loads from a directory. This loads charts only from directories.
(dir string)
| 43 | // |
| 44 | // This loads charts only from directories. |
| 45 | func LoadDir(dir string) (*chart.Chart, error) { |
| 46 | topdir, err := filepath.Abs(dir) |
| 47 | if err != nil { |
| 48 | return nil, err |
| 49 | } |
| 50 | |
| 51 | // Just used for errors. |
| 52 | c := &chart.Chart{} |
| 53 | |
| 54 | rules := ignore.Empty() |
| 55 | ifile := filepath.Join(topdir, ignore.HelmIgnore) |
| 56 | if _, err := os.Stat(ifile); err == nil { |
| 57 | r, err := ignore.ParseFile(ifile) |
| 58 | if err != nil { |
| 59 | return c, err |
| 60 | } |
| 61 | rules = r |
| 62 | } |
| 63 | rules.AddDefaults() |
| 64 | |
| 65 | files := []*archive.BufferedFile{} |
| 66 | topdir += string(filepath.Separator) |
| 67 | |
| 68 | walk := func(name string, fi os.FileInfo, err error) error { |
| 69 | n := strings.TrimPrefix(name, topdir) |
| 70 | if n == "" { |
| 71 | // No need to process top level. Avoid bug with helmignore .* matching |
| 72 | // empty names. See issue 1779. |
| 73 | return nil |
| 74 | } |
| 75 | |
| 76 | // Normalize to / since it will also work on Windows |
| 77 | n = filepath.ToSlash(n) |
| 78 | |
| 79 | if err != nil { |
| 80 | return err |
| 81 | } |
| 82 | if fi.IsDir() { |
| 83 | // Directory-based ignore rules should involve skipping the entire |
| 84 | // contents of that directory. |
| 85 | if rules.Ignore(n, fi) { |
| 86 | return filepath.SkipDir |
| 87 | } |
| 88 | return nil |
| 89 | } |
| 90 | |
| 91 | // If a .helmignore file matches, skip this file. |
| 92 | if rules.Ignore(n, fi) { |
| 93 | return nil |
| 94 | } |
| 95 | |
| 96 | // Irregular files include devices, sockets, and other uses of files that |
| 97 | // are not regular files. In Go they have a file mode type bit set. |
| 98 | // See https://golang.org/pkg/os/#FileMode for examples. |
| 99 | if !fi.Mode().IsRegular() { |
| 100 | return fmt.Errorf("cannot load irregular file %s as it has file mode type bits set", name) |
| 101 | } |
| 102 |
searching dependent graphs…