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"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ func matchExec(s string) (matches []string, longest string) {
|
|||||||
|
|
||||||
for _, f := range fi {
|
for _, f := range fi {
|
||||||
if strings.HasPrefix(f.Name(), s) {
|
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 {
|
if err != nil {
|
||||||
log.Printf("getting file information: %s", err)
|
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) {
|
func matchFile(s string) (matches []string, longest string) {
|
||||||
dir := strings.Replace(s, "~", envHome, -1)
|
dir := strings.Replace(s, "~", envHome, -1)
|
||||||
|
|
||||||
if !path.IsAbs(dir) {
|
if !filepath.IsAbs(dir) {
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("getting current directory: %s", err)
|
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)
|
fi, err := ioutil.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -117,17 +117,17 @@ func matchFile(s string) (matches []string, longest string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range fi {
|
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 {
|
if err != nil {
|
||||||
log.Printf("getting file information: %s", err)
|
log.Printf("getting file information: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, last := path.Split(s)
|
_, last := filepath.Split(s)
|
||||||
if strings.HasPrefix(f.Name(), last) {
|
if strings.HasPrefix(f.Name(), last) {
|
||||||
name := f.Name()
|
name := f.Name()
|
||||||
if isRoot(s) || path.Base(s) != s {
|
if isRoot(s) || filepath.Base(s) != s {
|
||||||
name = path.Join(path.Dir(s), f.Name())
|
name = filepath.Join(filepath.Dir(s), f.Name())
|
||||||
}
|
}
|
||||||
matches = append(matches, f.Name())
|
matches = append(matches, f.Name())
|
||||||
if longest != "" {
|
if longest != "" {
|
||||||
@@ -136,7 +136,7 @@ func matchFile(s string) (matches []string, longest string) {
|
|||||||
if f.Mode().IsRegular() {
|
if f.Mode().IsRegular() {
|
||||||
longest = name + " "
|
longest = name + " "
|
||||||
} else {
|
} else {
|
||||||
longest = name + "/"
|
longest = name + string(filepath.Separator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path/filepath"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -44,18 +44,18 @@ func init() {
|
|||||||
envHost = host
|
envHost = host
|
||||||
}
|
}
|
||||||
if envConfig == "" {
|
if envConfig == "" {
|
||||||
envConfig = path.Join(envHome, ".config")
|
envConfig = filepath.Join(envHome, ".config")
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp := os.TempDir()
|
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
|
// TODO: unique log file for each client
|
||||||
gLogPath = path.Join(tmp, fmt.Sprintf("lf.%s.log", envUser))
|
gLogPath = filepath.Join(tmp, fmt.Sprintf("lf.%s.log", envUser))
|
||||||
gServerLogPath = path.Join(tmp, fmt.Sprintf("lf.%s.server.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() {
|
func startServer() {
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"path"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"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
|
// 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
|
// purpose metric suffixes are used (e.g. 1K = 1000). For values less than 10
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -182,7 +182,7 @@ type Nav struct {
|
|||||||
func getDirs(wd string, height int) []*Dir {
|
func getDirs(wd string, height int) []*Dir {
|
||||||
var dirs []*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)
|
dir := newDir(curr)
|
||||||
for i, f := range dir.fi {
|
for i, f := range dir.fi {
|
||||||
if f.Name() == base {
|
if f.Name() == base {
|
||||||
@@ -285,7 +285,7 @@ func (nav *Nav) updir() error {
|
|||||||
|
|
||||||
nav.dirs = nav.dirs[:len(nav.dirs)-1]
|
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)
|
return fmt.Errorf("updir: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,8 +325,8 @@ func (nav *Nav) top() {
|
|||||||
func (nav *Nav) cd(wd string) error {
|
func (nav *Nav) cd(wd string) error {
|
||||||
wd = strings.Replace(wd, "~", envHome, -1)
|
wd = strings.Replace(wd, "~", envHome, -1)
|
||||||
|
|
||||||
if !path.IsAbs(wd) {
|
if !filepath.IsAbs(wd) {
|
||||||
wd = path.Join(nav.currDir().path, wd)
|
wd = filepath.Join(nav.currDir().path, wd)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.Chdir(wd); err != nil {
|
if err := os.Chdir(wd); err != nil {
|
||||||
@@ -417,7 +417,7 @@ func (nav *Nav) currFile() os.FileInfo {
|
|||||||
func (nav *Nav) currPath() string {
|
func (nav *Nav) currPath() string {
|
||||||
last := nav.dirs[len(nav.dirs)-1]
|
last := nav.dirs[len(nav.dirs)-1]
|
||||||
curr := last.fi[last.ind]
|
curr := last.fi[last.ind]
|
||||||
return path.Join(last.path, curr.Name())
|
return filepath.Join(last.path, curr.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *Nav) currMarks() []string {
|
func (nav *Nav) currMarks() []string {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -186,7 +186,7 @@ func (win *Win) printd(dir *Dir, marks map[string]bool) {
|
|||||||
fg = termbox.ColorWhite
|
fg = termbox.ColorWhite
|
||||||
}
|
}
|
||||||
|
|
||||||
path := path.Join(dir.path, f.Name())
|
path := filepath.Join(dir.path, f.Name())
|
||||||
|
|
||||||
if marks[path] {
|
if marks[path] {
|
||||||
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
||||||
|
|||||||
Reference in new issue
Block a user