forked from tcnksm/ghr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
local.go
53 lines (41 loc) · 943 Bytes
/
local.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
package main
import (
"os"
"path/filepath"
"github.com/pkg/errors"
)
// LocalAssets contains the local objects to be uploaded
func LocalAssets(path string) ([]string, error) {
if path == "" {
return []string{}, nil
}
path, err := filepath.Abs(path)
if err != nil {
return nil, errors.Wrap(err, "failed to get abs path")
}
fi, err := os.Stat(path)
if err != nil {
return nil, errors.Wrap(err, "failed to get file stat")
}
if !fi.IsDir() {
return []string{path}, nil
}
// Glob all files in the given path
files, err := filepath.Glob(filepath.Join(path, "*"))
if err != nil {
return nil, errors.Wrap(err, "failed to glob files")
}
assets := make([]string, 0, len(files))
for _, f := range files {
// Exclude directory.
if fi, _ := os.Stat(f); fi.IsDir() {
continue
}
// Exclude hidden file
if filepath.Base(f)[0] == '.' {
continue
}
assets = append(assets, f)
}
return assets, nil
}