Skip to content

Commit

Permalink
Add find and rsync match
Browse files Browse the repository at this point in the history
  • Loading branch information
zachhuff386 committed Sep 6, 2015
1 parent 0872f50 commit 1e84114
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
22 changes: 22 additions & 0 deletions utils/file.go
Expand Up @@ -228,6 +228,28 @@ func FindExt(path, ext string) (matches []string, err error) {
return
}

func FindMatch(path, match string) (matches []string, err error) {
files, err := ioutil.ReadDir(path)
if err != nil {
err = &ReadError{
errors.Wrapf(err, "utils: Failed to read dir '%s'", path),
}
return
}

for _, file := range files {
if file.IsDir() {
continue
}

if strings.Contains(file.Name(), match) {
matches = append(matches, filepath.Join(path, file.Name()))
}
}

return
}

func Filename(path string) string {
n := strings.LastIndex(path, "/")
if n == -1 {
Expand Down
20 changes: 20 additions & 0 deletions utils/rsync.go
Expand Up @@ -44,3 +44,23 @@ func RsyncExt(source, dest, ext string) (err error) {

return
}

func RsyncMatch(source, dest, match string) (err error) {
cmd := exec.Command("rsync", "-a", "-A", "-X",
"--include", "*"+match+"*", "--exclude", "*",
source+string(os.PathSeparator),
dest+string(os.PathSeparator))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

err = cmd.Run()
if err != nil {
err = &CopyError{
errors.Wrapf(err, "utils: Failed to rsync '%s' to '%s'", source,
dest),
}
return
}

return
}

0 comments on commit 1e84114

Please sign in to comment.