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 {

View File

@@ -1,17 +1,19 @@
package config
import "github.com/deranjer/gvc/common"
//Gvcconfig will be the struct that holds the entire client settings
type Gvcconfig struct {
Version string `toml:"version"`
RootPath string `toml:"rootpath"`
RepoName string `toml:"reponame"`
Remotes []Remote `toml:"remote"` //The remote servers for the repo
CurrentBranch string `toml:"currentbranch"`
LocalBranches []string `toml:"localbranches"` // LocalBranches constains a string list of branches on the local client. Names must be unique. \\TODO: someday add folders like git for branches
RemoteBranches []string `toml:"remotebranches"` // RemoteBranches constains a string list of branches on the server. Names must be unique. \\TODO: someday add folders like git for branches
Locked FileTypes `toml:"locked"`
Ignores FileTypes `toml:"ignore"` //These files will be ignored for all add functions
NoCompress FileTypes `toml:"nocompress"` //For binary compression some files should be ignored because the performance hit isn't worth the size savings
Version string `toml:"version"`
RootPath string `toml:"rootpath"`
RepoName string `toml:"reponame"`
Remotes []Remote `toml:"remote"` //The remote servers for the repo
CurrentBranch string `toml:"currentbranch"`
LocalBranches []string `toml:"localbranches"` // LocalBranches constains a string list of branches on the local client. Names must be unique. \\TODO: someday add folders like git for branches
RemoteBranches []string `toml:"remotebranches"` // RemoteBranches constains a string list of branches on the server. Names must be unique. \\TODO: someday add folders like git for branches
Locked common.FileTypes `toml:"locked"`
Ignores common.FileTypes `toml:"ignore"` //These files will be ignored for all add functions
NoCompress common.FileTypes `toml:"nocompress"` //For binary compression some files should be ignored because the performance hit isn't worth the size savings
}
//Remote will be a slice of remote server information
@@ -21,10 +23,3 @@ type Remote struct {
Port int `toml:"port"`
Default bool `toml:"default"` //Is this repo the default repo?
}
//FileTypes is for ignoring files to add or ignoring compress, or for locked files, all use the same type of struct (files, folders and exts)
type FileTypes struct {
Files []string `toml:"files"`
Exts []string `toml:"exts"`
Folders []string `toml:"folders"`
}