moving a function and struct over to a common library, starting on lockfile for server

This commit is contained in:
2020-06-07 23:26:13 -04:00
parent 6d738b138d
commit b2238657c8
12 changed files with 123 additions and 119 deletions

View File

@@ -6,10 +6,11 @@ import (
"path/filepath"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/common"
)
//AddFiles adds files to the repo, inputType specifies file, folder, wildcard or all
func AddFiles(input string, inputType string, ignore clientconfig.FileTypes) error {
func AddFiles(input string, inputType string, ignore common.FileTypes) error {
err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa
if err != nil {
return err
@@ -25,7 +26,7 @@ func AddFiles(input string, inputType string, ignore clientconfig.FileTypes) err
if err != nil {
return fmt.Errorf("unable to add file %s", err)
}
err = checkFileTypes(input, "file", ignore)
err = common.CheckFileTypes(input, "file", ignore)
if err != nil {
return fmt.Errorf("unable to add file as it (or ext) is on the ignores list %s", input)
}
@@ -49,9 +50,9 @@ func AddFiles(input string, inputType string, ignore clientconfig.FileTypes) err
return fmt.Errorf("failure accessing path %s", err)
}
if info.IsDir() {
err = checkFileTypes(currentFile, "folder", ignore)
err = common.CheckFileTypes(currentFile, "folder", ignore)
} else {
err = checkFileTypes(currentFile, "file", ignore)
err = common.CheckFileTypes(currentFile, "file", ignore)
}
if err != nil {
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
@@ -72,7 +73,7 @@ func AddFiles(input string, inputType string, ignore clientconfig.FileTypes) err
} else {
wildcard = input
}
err := checkFileTypes(wildcard, "wildcard", ignore)
err := common.CheckFileTypes(wildcard, "wildcard", ignore)
if err != nil {
return err
}
@@ -82,9 +83,9 @@ func AddFiles(input string, inputType string, ignore clientconfig.FileTypes) err
return fmt.Errorf("failure accessing path %s", err)
}
if info.IsDir() {
err = checkFileTypes(currentFile, "folder", ignore)
err = common.CheckFileTypes(currentFile, "folder", ignore)
} else {
err = checkFileTypes(currentFile, "file", ignore)
err = common.CheckFileTypes(currentFile, "file", ignore)
}
if err != nil {
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
@@ -108,9 +109,9 @@ func AddFiles(input string, inputType string, ignore clientconfig.FileTypes) err
return fmt.Errorf("failure accessing path %s", err)
}
if info.IsDir() {
err = checkFileTypes(currentFile, "folder", ignore)
err = common.CheckFileTypes(currentFile, "folder", ignore)
} else {
err = checkFileTypes(currentFile, "file", ignore)
err = common.CheckFileTypes(currentFile, "file", ignore)
}
if err != nil {
fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)

View File

@@ -31,36 +31,6 @@ func validateFileType(path string, inputType string) error {
return nil
}
func checkFileTypes(input string, inputType string, ignores clientconfig.FileTypes) error {
switch inputType {
case "file":
fileExt := filepath.Ext(input) // TODO more sanity checking on ext
for _, ignoredExt := range ignores.Exts {
if fileExt == ignoredExt {
return fmt.Errorf("file ext is on ignored list, cannot add file with file ext %s", fileExt)
}
}
for _, ignoredFile := range ignores.Files {
if input == ignoredFile {
return fmt.Errorf("file name is on ignored list, cannot add file with name %s", input)
}
}
case "folder":
for _, ignoredFolder := range ignores.Folders {
if input == ignoredFolder {
return fmt.Errorf("folder name is on the ignored list, cannot add folder with name %s", input)
}
}
case "wildcard":
for _, ignoredExt := range ignores.Exts {
if input == ignoredExt {
return fmt.Errorf("cannot add wildcard, since that ext is already added to the ignore config %s", input)
}
}
}
return nil
}
// FindServer finds the supplied server connection settings, creates a connection string and returns it
func FindServer(serverName string, branchName string, conf *clientconfig.Gvcconfig) (connectionString string, err error) {
if branchName == "" { // If no branch listed select master TODO: in future the 'default' branch will be their current branch

View File

@@ -4,18 +4,19 @@ import (
"fmt"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/common"
)
//IgnoreFiles ignores file(s)/folder based on name/wildcard, etc
func IgnoreFiles(input string, inputType string, conf *clientconfig.Gvcconfig) error {
err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa
err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa //TODO: Not needed I don't think we need user to be able to add ignores before files are there
if err != nil {
return err
}
ignore := conf.Ignores
switch inputType { // TODO: add default case for generic error handling
case "file":
err := checkFileTypes(input, "file", ignore)
err := common.CheckFileTypes(input, "file", ignore)
if err != nil {
return fmt.Errorf("%s already ignored: %s", input, err)
}
@@ -23,7 +24,7 @@ func IgnoreFiles(input string, inputType string, conf *clientconfig.Gvcconfig) e
conf.Ignores.Files = append(conf.Ignores.Files, input)
return nil
case "folder":
err := checkFileTypes(input, "folder", ignore)
err := common.CheckFileTypes(input, "folder", ignore)
if err != nil {
return fmt.Errorf("%s is already ignored: %s", input, err)
}
@@ -37,7 +38,7 @@ func IgnoreFiles(input string, inputType string, conf *clientconfig.Gvcconfig) e
} else {
wildcard = input
}
err := checkFileTypes(wildcard, "wildcard", ignore)
err := common.CheckFileTypes(wildcard, "wildcard", ignore)
if err != nil {
return fmt.Errorf("%s is already ignored: %s", input, err)
}
@@ -50,14 +51,14 @@ func IgnoreFiles(input string, inputType string, conf *clientconfig.Gvcconfig) e
// RemoveIgnoreFiles removes files/folders/wildcards from the ignore list
func RemoveIgnoreFiles(input string, inputType string, conf *clientconfig.Gvcconfig) error {
err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa
err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa //TODO: Not needed I don't think we need user to be able to add ignores before files are there
if err != nil {
return err
}
ignore := conf.Ignores
switch inputType { // TODO: add default case for generic error handling
case "file":
err := checkFileTypes(input, "file", ignore)
err := common.CheckFileTypes(input, "file", ignore)
if err != nil {
fmt.Println("Removing file from ignores: ", input)
for i, fileIgnore := range ignore.Files {
@@ -72,7 +73,7 @@ func RemoveIgnoreFiles(input string, inputType string, conf *clientconfig.Gvccon
fmt.Println("File not found in ingores, unable to remove: ", input)
return nil
case "folder":
err := checkFileTypes(input, "folder", ignore)
err := common.CheckFileTypes(input, "folder", ignore)
if err != nil {
for i, folderIgnore := range ignore.Folders {
if input == folderIgnore {
@@ -92,7 +93,7 @@ func RemoveIgnoreFiles(input string, inputType string, conf *clientconfig.Gvccon
} else {
wildcard = input
}
err := checkFileTypes(wildcard, "wildcard", ignore)
err := common.CheckFileTypes(wildcard, "wildcard", ignore)
if err != nil {
for i, wildcardIgnore := range ignore.Exts {
if input == wildcardIgnore {

View File

@@ -4,6 +4,7 @@ import (
"fmt"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/common"
)
//LockFiles locks file(s)/folder based on name/wildcard, etc
@@ -15,7 +16,7 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err
locked := conf.Locked
switch inputType { // TODO: add default case for generic error handling
case "file":
err := checkFileTypes(input, "file", locked)
err := common.CheckFileTypes(input, "file", locked)
if err != nil {
return fmt.Errorf("%s already locked: %s", input, err)
}
@@ -23,7 +24,7 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err
conf.Locked.Files = append(conf.Locked.Files, input)
return nil
case "folder":
err := checkFileTypes(input, "folder", locked)
err := common.CheckFileTypes(input, "folder", locked)
if err != nil {
return fmt.Errorf("%s is already locked: %s", input, err)
}
@@ -37,7 +38,7 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err
} else {
wildcard = input
}
err := checkFileTypes(wildcard, "wildcard", locked)
err := common.CheckFileTypes(wildcard, "wildcard", locked)
if err != nil {
return fmt.Errorf("%s is already locked: %s", input, err)
}
@@ -57,7 +58,7 @@ func RemoveLockFiles(input string, inputType string, conf *clientconfig.Gvcconfi
locked := conf.Locked
switch inputType { // TODO: add default case for generic error handling
case "file":
err := checkFileTypes(input, "file", locked)
err := common.CheckFileTypes(input, "file", locked)
if err != nil {
fmt.Println("Removing file from locked: ", input)
for i, fileLock := range locked.Files {
@@ -72,7 +73,7 @@ func RemoveLockFiles(input string, inputType string, conf *clientconfig.Gvcconfi
fmt.Println("File not found in ingores, unable to remove: ", input)
return nil
case "folder":
err := checkFileTypes(input, "folder", locked)
err := common.CheckFileTypes(input, "folder", locked)
if err != nil {
for i, folderLock := range locked.Folders {
if input == folderLock {
@@ -92,7 +93,7 @@ func RemoveLockFiles(input string, inputType string, conf *clientconfig.Gvcconfi
} else {
wildcard = input
}
err := checkFileTypes(wildcard, "wildcard", locked)
err := common.CheckFileTypes(wildcard, "wildcard", locked)
if err != nil {
for i, wildcardLock := range locked.Exts {
if input == wildcardLock {