-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d141edd
commit d11b6bf
Showing
10 changed files
with
212 additions
and
105 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package fsutil | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/mattn/go-zglob" | ||
) | ||
|
||
func adjustRel(newroot string, files []Hostfile) []Hostfile { | ||
out := []Hostfile{} | ||
for _, f := range files { | ||
f.Rel = filepath.Join(newroot, f.Rel) | ||
out = append(out, f) | ||
} | ||
return out | ||
} | ||
|
||
// Glob returns a list of HostFile objects matching pattern or nil if there is no matching file. | ||
// This method uses the implementation in github.com/mattn/go-zglob. | ||
func Glob(pattern string) ([]Hostfile, error) { | ||
var files []Hostfile | ||
matches, err := zglob.Glob(pattern) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, path := range matches { | ||
finfo, err := os.Stat(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if finfo.IsDir() { | ||
dfiles, err := WalkFiles(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
dfiles = adjustRel(path, dfiles) | ||
files = append(files, dfiles...) | ||
continue | ||
} | ||
absPath, err := filepath.Abs(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
files = append(files, Hostfile{ | ||
Rel: path, | ||
Abs: absPath, | ||
Size: finfo.Size(), | ||
LastModified: finfo.ModTime(), | ||
}) | ||
} | ||
return files, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters