From c2ab0c9a9bad2bd7d56d34b919f9d737e4a3822d Mon Sep 17 00:00:00 2001 From: David Symonds Date: Thu, 18 Jul 2013 15:53:59 +1000 Subject: [PATCH] Use path/filepath instead of path for manipulating OS paths. --- glog.go | 6 +++--- glog_file.go | 8 ++++---- glog_test.go | 5 ++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/glog.go b/glog.go index 8927f93e9..e95159374 100644 --- a/glog.go +++ b/glog.go @@ -42,7 +42,7 @@ import ( "fmt" "io" "os" - "path" + "path/filepath" "runtime" "strconv" "strings" @@ -214,7 +214,7 @@ func (m *modulePat) match(file string) bool { if m.literal { return file == m.pattern } - match, _ := path.Match(m.pattern, file) + match, _ := filepath.Match(m.pattern, file) return match } @@ -828,7 +828,7 @@ func (l *loggingT) flushAll() { // setV computes and remembers the V level for a given PC // when vmodule is enabled. // 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++. // l.mu is held. func (l *loggingT) setV(pc uintptr) Level { diff --git a/glog_file.go b/glog_file.go index 097a8e7d0..1a1ed66df 100644 --- a/glog_file.go +++ b/glog_file.go @@ -24,7 +24,7 @@ import ( "fmt" "os" "os/user" - "path" + "path/filepath" "strings" "sync" "time" @@ -49,7 +49,7 @@ func createLogDirs() { var ( pid = os.Getpid() - program = path.Base(os.Args[0]) + program = filepath.Base(os.Args[0]) host = "unknownhost" 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) var lastErr error for _, dir := range logDirs { - fname := path.Join(dir, name) + fname := filepath.Join(dir, name) f, err := os.Create(fname) if err == nil { - symlink := path.Join(dir, link) + symlink := filepath.Join(dir, link) os.Remove(symlink) // ignore err os.Symlink(fname, symlink) // ignore err return f, fname, nil diff --git a/glog_test.go b/glog_test.go index 92ccc46bf..e4cac5a52 100644 --- a/glog_test.go +++ b/glog_test.go @@ -19,6 +19,7 @@ package glog import ( "bytes" "fmt" + "path/filepath" "runtime" "strings" "testing" @@ -299,9 +300,7 @@ func TestLogBacktraceAt(t *testing.T) { if !ok { 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) err := logging.traceLocation.Set(infoLine) if err != nil {