Use filepath package throughout for Windows support
The "path" package supports only forward slashes in paths, like those found in *nix operating systems or URLs. Meanwhile Windows with its CP/M and QDOS ancestry requires drive letters and backslashes, and thus the "filepath" package needs to be used.
This commit is contained in:
parent
72ff78498b
commit
edb42a0e3b
@ -26,7 +26,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/naoina/toml"
|
"github.com/naoina/toml"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
@ -50,7 +50,7 @@ func newConfig(filename string) (*config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
conf := &config{handled: make(map[string]bool)}
|
conf := &config{handled: make(map[string]bool)}
|
||||||
switch path.Ext(filename) {
|
switch filepath.Ext(filename) {
|
||||||
case ".json":
|
case ".json":
|
||||||
if err := json.Unmarshal(bytes, &conf); err != nil {
|
if err := json.Unmarshal(bytes, &conf); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -27,7 +27,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func usage() {
|
func usage() {
|
||||||
fmt.Fprintf(os.Stderr, "Usage: %s [options] conf src\n", path.Base(os.Args[0]))
|
fmt.Fprintf(os.Stderr, "Usage: %s [options] conf src\n", filepath.Base(os.Args[0]))
|
||||||
fmt.Fprintf(os.Stderr, "https://foosoft.net/projects/homemaker/\n\n")
|
fmt.Fprintf(os.Stderr, "https://foosoft.net/projects/homemaker/\n\n")
|
||||||
fmt.Fprintf(os.Stderr, "Parameters:\n")
|
fmt.Fprintf(os.Stderr, "Parameters:\n")
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
|
10
link.go
10
link.go
@ -26,7 +26,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -65,13 +65,13 @@ func processLink(params []string, conf *config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
srcPathAbs := srcPath
|
srcPathAbs := srcPath
|
||||||
if !path.IsAbs(srcPathAbs) {
|
if !filepath.IsAbs(srcPathAbs) {
|
||||||
srcPathAbs = path.Join(conf.srcDir, srcPath)
|
srcPathAbs = filepath.Join(conf.srcDir, srcPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
dstPathAbs := dstPath
|
dstPathAbs := dstPath
|
||||||
if !path.IsAbs(dstPathAbs) {
|
if !filepath.IsAbs(dstPathAbs) {
|
||||||
dstPathAbs = path.Join(conf.dstDir, dstPath)
|
dstPathAbs = filepath.Join(conf.dstDir, dstPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.flags&flagUnlink != flagUnlink {
|
if conf.flags&flagUnlink != flagUnlink {
|
||||||
|
10
template.go
10
template.go
@ -26,7 +26,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
@ -79,13 +79,13 @@ func processTemplate(params []string, conf *config) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
srcPathAbs := srcPath
|
srcPathAbs := srcPath
|
||||||
if !path.IsAbs(srcPathAbs) {
|
if !filepath.IsAbs(srcPathAbs) {
|
||||||
srcPathAbs = path.Join(conf.srcDir, srcPath)
|
srcPathAbs = filepath.Join(conf.srcDir, srcPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
dstPathAbs := dstPath
|
dstPathAbs := dstPath
|
||||||
if !path.IsAbs(dstPathAbs) {
|
if !filepath.IsAbs(dstPathAbs) {
|
||||||
dstPathAbs = path.Join(conf.dstDir, dstPath)
|
dstPathAbs = filepath.Join(conf.dstDir, dstPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = os.Stat(srcPathAbs); os.IsNotExist(err) {
|
if _, err = os.Stat(srcPathAbs); os.IsNotExist(err) {
|
||||||
|
3
util.go
3
util.go
@ -26,7 +26,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -78,7 +77,7 @@ func cleanPath(loc string, flags int) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createPath(loc string, flags int, mode os.FileMode) error {
|
func createPath(loc string, flags int, mode os.FileMode) error {
|
||||||
parentDir := path.Dir(loc)
|
parentDir := filepath.Dir(loc)
|
||||||
|
|
||||||
if _, err := os.Stat(parentDir); os.IsNotExist(err) {
|
if _, err := os.Stat(parentDir); os.IsNotExist(err) {
|
||||||
if flags&flagForce != 0 || prompt("force create path", parentDir) {
|
if flags&flagForce != 0 || prompt("force create path", parentDir) {
|
||||||
|
Loading…
Reference in New Issue
Block a user