Skip to content

Commit

Permalink
fix file path error for windows import issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarroll committed Jul 16, 2014
1 parent a749a67 commit 9095b44
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 140 deletions.
2 changes: 1 addition & 1 deletion fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func runFetch(cmd *Command, args []string) {
}
//Handle expanding static resources into a "bundle" folder
if isResource && expandResources && name != "package.xml" {
pathParts := strings.Split(name, "/")
pathParts := strings.Split(name, string(os.PathSeparator))
resourceName := pathParts[cap(pathParts)-1]

resourceExt := strings.Split(resourceName, ".")[1]
Expand Down
3 changes: 2 additions & 1 deletion import.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ func runImport(cmd *Command, args []string) {
if _, err := os.Stat(filepath.Join(root, "package.xml")); os.IsNotExist(err) {
ErrorAndExit("Must specify a directory that contains metadata files")
}

err := filepath.Walk(root, func(path string, f os.FileInfo, err error) error {
if f.Mode().IsRegular() {
if f.Name() != ".DS_Store" {
data, err := ioutil.ReadFile(path)
if err != nil {
ErrorAndExit(err.Error())
}
files[strings.Replace(path, fmt.Sprintf("%s/", root), "", -1)] = data
files[strings.Replace(path, fmt.Sprintf("%s%s", root, string(os.PathSeparator)), "", -1)] = data
}
}
return nil
Expand Down
143 changes: 5 additions & 138 deletions metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -497,128 +498,6 @@ func NewForceMetadata(force *Force) (fm *ForceMetadata) {
return
}

// Example of how to use Go's reflection
// Print the attributes of a Data Model
/*func getAttributes(m interface{}) map[string]reflect.StructField {
typ := reflect.TypeOf(m)
// if a pointer to a struct is passed, get the type of the dereferenced object
if typ.Kind() == reflect.Ptr {
typ = typ.Elem()
}
// create an attribute data structure as a map of types keyed by a string.
attrs := make(map[string]reflect.StructField)
// Only structs are supported so return an empty result if the passed object
// isn't a struct
if typ.Kind() != reflect.Struct {
fmt.Printf("%v type can't have attributes inspected\n", typ.Kind())
return attrs
}
// loop through the struct's fields and set the map
for i := 0; i < typ.NumField(); i++ {
p := typ.Field(i)
if !p.Anonymous {
attrs[strings.ToLower(p.Name)] = p
}
}
return attrs
}*/

/*func ValidateOptionsAndDefaults(typ string, fields map[string]reflect.StructField, requiredDefaults reflect.Value, options map[string]string) (newOptions map[string]string, err error) {
newOptions = make(map[string]string)
// validate optional attributes
for name, value := range options {
field, ok := fields[strings.ToLower(name)]
if !ok {
ErrorAndExit(fmt.Sprintf("validation error: %s:%s is not a valid option for field type %s", name, value, typ))
} else {
newOptions[field.Tag.Get("xml")] = options[name]
}
}
// validate required attributes
s := requiredDefaults
tod := s.Type()
for i := 0; i < s.NumField(); i++ {
_, ok := options[strings.ToLower(tod.Field(i).Name)]
if !ok {
switch s.Field(i).Type().Name() {
case "int":
newOptions[tod.Field(i).Tag.Get("xml")] = strconv.Itoa(s.Field(i).Interface().(int))
break
case "bool":
newOptions[tod.Field(i).Tag.Get("xml")] = strconv.FormatBool(s.Field(i).Interface().(bool))
break
default:
newOptions[tod.Field(i).Tag.Get("xml")] = s.Field(i).Interface().(string)
break
}
} else {
newOptions[tod.Field(i).Tag.Get("xml")] = options[strings.ToLower(tod.Field(i).Name)]
}
}
return newOptions, err
}
func (fm *ForceMetadata) ValidateFieldOptions(typ string, options map[string]string) (newOptions map[string]string, err error) {
newOptions = make(map[string]string)
var attrs map[string]reflect.StructField
var s reflect.Value
switch typ {
case "string", "text":
attrs = getAttributes(&StringField{})
s = reflect.ValueOf(&StringFieldRequired{255}).Elem()
break
case "textarea":
attrs = getAttributes(&TextAreaField{})
s = reflect.ValueOf(&TextAreaFieldRequired{}).Elem()
break
case "longtextarea":
attrs = getAttributes(&LongTextAreaField{})
s = reflect.ValueOf(&LongTextAreaFieldRequired{32768, 5}).Elem()
break
case "richtextarea":
attrs = getAttributes(&RichTextAreaField{})
s = reflect.ValueOf(&RichTextAreaFieldRequired{32768, 5}).Elem()
break
case "bool", "boolean", "checkbox":
attrs = getAttributes(&BoolField{})
s = reflect.ValueOf(&BoolFieldRequired{false}).Elem()
break
case "datetime":
attrs = getAttributes(&DatetimeField{})
s = reflect.ValueOf(&DatetimeFieldRequired{}).Elem()
break
case "float":
attrs = getAttributes(&FloatField{})
s = reflect.ValueOf(&FloatFieldRequired{16, 2}).Elem()
break
case "number", "int":
attrs = getAttributes(&NumberField{})
s = reflect.ValueOf(&NumberFieldRequired{18, 0}).Elem()
break
case "autonumber":
attrs = getAttributes(&AutoNumberField{})
s = reflect.ValueOf(&AutoNumberFieldRequired{0, "AN-{00000}"}).Elem()
break
case "geolocation":
attrs = getAttributes(&GeolocationField{})
s = reflect.ValueOf(&GeolocationFieldRequired{true, 5}).Elem()
break
default:
break
}
newOptions, err = ValidateOptionsAndDefaults(typ, attrs, s, options)
return newOptions, nil
}*/

func (fm *ForceMetadata) CheckStatus(id string) (err error) {
body, err := fm.soapExecute("checkStatus", fmt.Sprintf("<id>%s</id>", id))
if err != nil {
Expand Down Expand Up @@ -647,8 +526,6 @@ func (fm *ForceMetadata) CheckDeployStatus(id string) (results ForceCheckDeploym
return
}

//fmt.Println("CDS: \n" + string(body))

var deployResult struct {
Results ForceCheckDeploymentStatusResult `xml:"Body>checkDeployStatusResponse>result"`
}
Expand All @@ -657,15 +534,6 @@ func (fm *ForceMetadata) CheckDeployStatus(id string) (results ForceCheckDeploym
ErrorAndExit(err.Error())
}

/*if !deployResult.Results.Success {
//ErrorAndExit("Push failed, there were %v components with errors\nID: %v", deployResult.Results.NumberComponentErrors, deployResult.Results.Id)
}
var result struct {
Problems []ForceMetadataDeployProblem `xml:"Body>checkDeployStatusResponse>result>messages"`
}
if err = xml.Unmarshal(body, &result); err != nil {
return
}*/
results = deployResult.Results
return
}
Expand Down Expand Up @@ -1009,7 +877,8 @@ func (fm *ForceMetadata) Deploy(files ForceMetadataFiles, options ForceDeployOpt
zipfile := new(bytes.Buffer)
zipper := zip.NewWriter(zipfile)
for name, data := range files {
wr, err := zipper.Create(fmt.Sprintf("unpackaged/%s", name))
fname := filepath.Base(name)
wr, err := zipper.Create(fmt.Sprintf("unpackaged%s%s", string(os.PathSeparator), fname))
if err != nil {
return nil, nil, err
}
Expand All @@ -1023,8 +892,6 @@ func (fm *ForceMetadata) Deploy(files ForceMetadataFiles, options ForceDeployOpt
return
}

//fmt.Println(string(body))

var status struct {
Id string `xml:"Body>deployResponse>result>id"`
}
Expand Down Expand Up @@ -1084,7 +951,7 @@ func (fm *ForceMetadata) Retrieve(query ForceMetadataQuery) (files ForceMetadata
}
files = make(ForceMetadataFiles)
for raw_name, data := range raw_files {
name := strings.Replace(raw_name, "unpackaged/", "", -1)
name := strings.Replace(raw_name, fmt.Sprintf("unpackaged%s", string(os.PathSeparator)), "", -1)
files[name] = data
}
return
Expand Down Expand Up @@ -1117,7 +984,7 @@ func (fm *ForceMetadata) RetrievePackage(packageName string) (files ForceMetadat
}
files = make(ForceMetadataFiles)
for raw_name, data := range raw_files {
name := strings.Replace(raw_name, "unpackaged/", "", -1)
name := strings.Replace(raw_name, fmt.Sprintf("unpackaged%s", string(os.PathSeparator)), "", -1)
files[name] = data
}
return
Expand Down

0 comments on commit 9095b44

Please sign in to comment.