some optimization for add files

This commit is contained in:
2020-05-28 21:29:50 -04:00
parent 8c59c4b067
commit 6ae1705ef0
3 changed files with 65 additions and 21 deletions

View File

@@ -10,9 +10,13 @@ import (
//AddFiles adds files to the repo, inputType specifies file, folder, wildcard or all
func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error {
workingDir, err := os.Getwd()
if err != nil {
return err
}
var trackedFiles []string
switch inputType {
case "file":
case "file": // If the -file flag was used, then make sure it is a file, make sure not on ignore list, then add it to tracked files
_, err := os.Stat(input)
if err != nil {
return fmt.Errorf("unable to add file %s", err)
@@ -21,10 +25,6 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
if err != nil {
return fmt.Errorf("unable to add file as it (or ext) is on the ignores list %s", input)
}
workingDir, err := os.Getwd()
if err != nil {
return err
}
relativePath, err := filepath.Rel(workingDir, input)
if err != nil {
return fmt.Errorf("unable to create relative path for file: %s", err)
@@ -39,10 +39,6 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
if !folder.IsDir() {
return fmt.Errorf("file exists, but is not a folder %s", err)
}
workingDir, err := os.Getwd()
if err != nil {
return err
}
filepath.Walk(input, func(path string, info os.FileInfo, err error) error {
currentFile := filepath.Base(path)
if err != nil {
@@ -66,7 +62,6 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
return nil
})
case "wildcard":
fmt.Println("First char, ", input[:1])
var wildcard string
if input[:1] == "*" { // Removing the wildcard char since we don't store that or test with that char
wildcard = input[1:]
@@ -77,10 +72,6 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
if err != nil {
return err
}
workingDir, err := os.Getwd()
if err != nil {
return err
}
filepath.Walk(workingDir, func(path string, info os.FileInfo, err error) error {
currentFile := filepath.Base(path) // Stripping all the pathing so we just get the filename
if err != nil {
@@ -107,10 +98,6 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
return nil
})
case "all":
workingDir, err := os.Getwd()
if err != nil {
return err
}
filepath.Walk(workingDir, func(path string, info os.FileInfo, err error) error {
currentFile := filepath.Base(path)
if err != nil {
@@ -136,8 +123,7 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
return nil
})
}
fmt.Println("Added tracked files", trackedFiles)
fmt.Println("Added tracked files", trackedFiles) // Print out all the new tracked files
return nil
}

View File

@@ -3,10 +3,12 @@ package clientcmd
import (
"fmt"
"os"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
)
//IgnoreFiles ignores file(s)/folder based on name/wildcard, etc
func IgnoreFiles() error {
func IgnoreFiles(input string, inputType string, ignore clientconfig.Ignore) error {
fmt.Println("File/folder/wildcard to ignore", os.Args[2])
return nil
}