Forráskód Böngészése

Use path/filepath instead of path for manipulating OS paths.

David Symonds 12 éve
szülő
commit
c2ab0c9a9b
3 módosított fájl, 9 hozzáadás és 10 törlés
  1. 3 3
      glog.go
  2. 4 4
      glog_file.go
  3. 2 3
      glog_test.go

+ 3 - 3
glog.go

@@ -42,7 +42,7 @@ import (
 	"fmt"
 	"fmt"
 	"io"
 	"io"
 	"os"
 	"os"
-	"path"
+	"path/filepath"
 	"runtime"
 	"runtime"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
@@ -214,7 +214,7 @@ func (m *modulePat) match(file string) bool {
 	if m.literal {
 	if m.literal {
 		return file == m.pattern
 		return file == m.pattern
 	}
 	}
-	match, _ := path.Match(m.pattern, file)
+	match, _ := filepath.Match(m.pattern, file)
 	return match
 	return match
 }
 }
 
 
@@ -828,7 +828,7 @@ func (l *loggingT) flushAll() {
 // setV computes and remembers the V level for a given PC
 // setV computes and remembers the V level for a given PC
 // when vmodule is enabled.
 // when vmodule is enabled.
 // File pattern matching takes the basename of the file, stripped
 // File pattern matching takes the basename of the file, stripped
-// of its .go suffix, and uses path.Match, which is a little more
+// of its .go suffix, and uses filepath.Match, which is a little more
 // general than the *? matching used in C++.
 // general than the *? matching used in C++.
 // l.mu is held.
 // l.mu is held.
 func (l *loggingT) setV(pc uintptr) Level {
 func (l *loggingT) setV(pc uintptr) Level {

+ 4 - 4
glog_file.go

@@ -24,7 +24,7 @@ import (
 	"fmt"
 	"fmt"
 	"os"
 	"os"
 	"os/user"
 	"os/user"
-	"path"
+	"path/filepath"
 	"strings"
 	"strings"
 	"sync"
 	"sync"
 	"time"
 	"time"
@@ -49,7 +49,7 @@ func createLogDirs() {
 
 
 var (
 var (
 	pid      = os.Getpid()
 	pid      = os.Getpid()
-	program  = path.Base(os.Args[0])
+	program  = filepath.Base(os.Args[0])
 	host     = "unknownhost"
 	host     = "unknownhost"
 	userName = "unknownuser"
 	userName = "unknownuser"
 )
 )
@@ -107,10 +107,10 @@ func create(tag string, t time.Time) (f *os.File, filename string, err error) {
 	name, link := logName(tag, t)
 	name, link := logName(tag, t)
 	var lastErr error
 	var lastErr error
 	for _, dir := range logDirs {
 	for _, dir := range logDirs {
-		fname := path.Join(dir, name)
+		fname := filepath.Join(dir, name)
 		f, err := os.Create(fname)
 		f, err := os.Create(fname)
 		if err == nil {
 		if err == nil {
-			symlink := path.Join(dir, link)
+			symlink := filepath.Join(dir, link)
 			os.Remove(symlink)         // ignore err
 			os.Remove(symlink)         // ignore err
 			os.Symlink(fname, symlink) // ignore err
 			os.Symlink(fname, symlink) // ignore err
 			return f, fname, nil
 			return f, fname, nil

+ 2 - 3
glog_test.go

@@ -19,6 +19,7 @@ package glog
 import (
 import (
 	"bytes"
 	"bytes"
 	"fmt"
 	"fmt"
+	"path/filepath"
 	"runtime"
 	"runtime"
 	"strings"
 	"strings"
 	"testing"
 	"testing"
@@ -299,9 +300,7 @@ func TestLogBacktraceAt(t *testing.T) {
 		if !ok {
 		if !ok {
 			t.Fatal("could not get file:line")
 			t.Fatal("could not get file:line")
 		}
 		}
-		if i := strings.LastIndex(file, "/"); i >= 0 {
-			file = file[i+1:]
-		}
+		_, file = filepath.Split(file)
 		infoLine = fmt.Sprintf("%s:%d", file, line+delta)
 		infoLine = fmt.Sprintf("%s:%d", file, line+delta)
 		err := logging.traceLocation.Set(infoLine)
 		err := logging.traceLocation.Set(infoLine)
 		if err != nil {
 		if err != nil {