use filepath module instead of path for portability
This should fix path separator confusion in windows. Mentioned in #12.
This commit is contained in:
1 parent
90c282e1ec
commit
3d493e8271
5 files changed
+26
-26
No files matched your search
@@ -4,7 +4,7 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -72,7 +72,7 @@ func matchExec(s string) (matches []string, longest string) {
|
||||
|
||||
for _, f := range fi {
|
||||
if strings.HasPrefix(f.Name(), s) {
|
||||
f, err = os.Stat(path.Join(p, f.Name()))
|
||||
f, err = os.Stat(filepath.Join(p, f.Name()))
|
||||
if err != nil {
|
||||
log.Printf("getting file information: %s", err)
|
||||
}
|
||||
@@ -101,15 +101,15 @@ func matchExec(s string) (matches []string, longest string) {
|
||||
func matchFile(s string) (matches []string, longest string) {
|
||||
dir := strings.Replace(s, "~", envHome, -1)
|
||||
|
||||
if !path.IsAbs(dir) {
|
||||
if !filepath.IsAbs(dir) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
}
|
||||
dir = wd + "/" + dir
|
||||
dir = wd + string(filepath.Separator) + dir
|
||||
}
|
||||
|
||||
dir = path.Dir(dir)
|
||||
dir = filepath.Dir(dir)
|
||||
|
||||
fi, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
@@ -117,17 +117,17 @@ func matchFile(s string) (matches []string, longest string) {
|
||||
}
|
||||
|
||||
for _, f := range fi {
|
||||
f, err := os.Stat(path.Join(dir, f.Name()))
|
||||
f, err := os.Stat(filepath.Join(dir, f.Name()))
|
||||
if err != nil {
|
||||
log.Printf("getting file information: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, last := path.Split(s)
|
||||
_, last := filepath.Split(s)
|
||||
if strings.HasPrefix(f.Name(), last) {
|
||||
name := f.Name()
|
||||
if isRoot(s) || path.Base(s) != s {
|
||||
name = path.Join(path.Dir(s), f.Name())
|
||||
if isRoot(s) || filepath.Base(s) != s {
|
||||
name = filepath.Join(filepath.Dir(s), f.Name())
|
||||
}
|
||||
matches = append(matches, f.Name())
|
||||
if longest != "" {
|
||||
@@ -136,7 +136,7 @@ func matchFile(s string) (matches []string, longest string) {
|
||||
if f.Mode().IsRegular() {
|
||||
longest = name + " "
|
||||
} else {
|
||||
longest = name + "/"
|
||||
longest = name + string(filepath.Separator)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime/pprof"
|
||||
)
|
||||
|
||||
@@ -44,18 +44,18 @@ func init() {
|
||||
envHost = host
|
||||
}
|
||||
if envConfig == "" {
|
||||
envConfig = path.Join(envHome, ".config")
|
||||
envConfig = filepath.Join(envHome, ".config")
|
||||
}
|
||||
|
||||
tmp := os.TempDir()
|
||||
|
||||
gSocketPath = path.Join(tmp, fmt.Sprintf("lf.%s.sock", envUser))
|
||||
gSocketPath = filepath.Join(tmp, fmt.Sprintf("lf.%s.sock", envUser))
|
||||
|
||||
// TODO: unique log file for each client
|
||||
gLogPath = path.Join(tmp, fmt.Sprintf("lf.%s.log", envUser))
|
||||
gServerLogPath = path.Join(tmp, fmt.Sprintf("lf.%s.server.log", envUser))
|
||||
gLogPath = filepath.Join(tmp, fmt.Sprintf("lf.%s.log", envUser))
|
||||
gServerLogPath = filepath.Join(tmp, fmt.Sprintf("lf.%s.server.log", envUser))
|
||||
|
||||
gConfigPath = path.Join(envConfig, "lf", "lfrc")
|
||||
gConfigPath = filepath.Join(envConfig, "lf", "lfrc")
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
|
||||
@@ -3,13 +3,13 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func isRoot(name string) bool { return path.Dir(name) == name }
|
||||
func isRoot(name string) bool { return filepath.Dir(name) == name }
|
||||
|
||||
// This function converts a size in bytes to a human readable form. For this
|
||||
// purpose metric suffixes are used (e.g. 1K = 1000). For values less than 10
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
@@ -182,7 +182,7 @@ type Nav struct {
|
||||
func getDirs(wd string, height int) []*Dir {
|
||||
var dirs []*Dir
|
||||
|
||||
for curr, base := wd, ""; !isRoot(base); curr, base = path.Dir(curr), path.Base(curr) {
|
||||
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
|
||||
dir := newDir(curr)
|
||||
for i, f := range dir.fi {
|
||||
if f.Name() == base {
|
||||
@@ -285,7 +285,7 @@ func (nav *Nav) updir() error {
|
||||
|
||||
nav.dirs = nav.dirs[:len(nav.dirs)-1]
|
||||
|
||||
if err := os.Chdir(path.Dir(dir.path)); err != nil {
|
||||
if err := os.Chdir(filepath.Dir(dir.path)); err != nil {
|
||||
return fmt.Errorf("updir: %s", err)
|
||||
}
|
||||
|
||||
@@ -325,8 +325,8 @@ func (nav *Nav) top() {
|
||||
func (nav *Nav) cd(wd string) error {
|
||||
wd = strings.Replace(wd, "~", envHome, -1)
|
||||
|
||||
if !path.IsAbs(wd) {
|
||||
wd = path.Join(nav.currDir().path, wd)
|
||||
if !filepath.IsAbs(wd) {
|
||||
wd = filepath.Join(nav.currDir().path, wd)
|
||||
}
|
||||
|
||||
if err := os.Chdir(wd); err != nil {
|
||||
@@ -417,7 +417,7 @@ func (nav *Nav) currFile() os.FileInfo {
|
||||
func (nav *Nav) currPath() string {
|
||||
last := nav.dirs[len(nav.dirs)-1]
|
||||
curr := last.fi[last.ind]
|
||||
return path.Join(last.path, curr.Name())
|
||||
return filepath.Join(last.path, curr.Name())
|
||||
}
|
||||
|
||||
func (nav *Nav) currMarks() []string {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -186,7 +186,7 @@ func (win *Win) printd(dir *Dir, marks map[string]bool) {
|
||||
fg = termbox.ColorWhite
|
||||
}
|
||||
|
||||
path := path.Join(dir.path, f.Name())
|
||||
path := filepath.Join(dir.path, f.Name())
|
||||
|
||||
if marks[path] {
|
||||
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
||||
|
||||
Reference in new issue
Block a user