Skip to content

Commit c2ab0c9

Browse files
committed
Use path/filepath instead of path for manipulating OS paths.
1 parent 47832e5 commit c2ab0c9

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

glog.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
"fmt"
4343
"io"
4444
"os"
45-
"path"
45+
"path/filepath"
4646
"runtime"
4747
"strconv"
4848
"strings"
@@ -214,7 +214,7 @@ func (m *modulePat) match(file string) bool {
214214
if m.literal {
215215
return file == m.pattern
216216
}
217-
match, _ := path.Match(m.pattern, file)
217+
match, _ := filepath.Match(m.pattern, file)
218218
return match
219219
}
220220

@@ -828,7 +828,7 @@ func (l *loggingT) flushAll() {
828828
// setV computes and remembers the V level for a given PC
829829
// when vmodule is enabled.
830830
// File pattern matching takes the basename of the file, stripped
831-
// of its .go suffix, and uses path.Match, which is a little more
831+
// of its .go suffix, and uses filepath.Match, which is a little more
832832
// general than the *? matching used in C++.
833833
// l.mu is held.
834834
func (l *loggingT) setV(pc uintptr) Level {

glog_file.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"fmt"
2525
"os"
2626
"os/user"
27-
"path"
27+
"path/filepath"
2828
"strings"
2929
"sync"
3030
"time"
@@ -49,7 +49,7 @@ func createLogDirs() {
4949

5050
var (
5151
pid = os.Getpid()
52-
program = path.Base(os.Args[0])
52+
program = filepath.Base(os.Args[0])
5353
host = "unknownhost"
5454
userName = "unknownuser"
5555
)
@@ -107,10 +107,10 @@ func create(tag string, t time.Time) (f *os.File, filename string, err error) {
107107
name, link := logName(tag, t)
108108
var lastErr error
109109
for _, dir := range logDirs {
110-
fname := path.Join(dir, name)
110+
fname := filepath.Join(dir, name)
111111
f, err := os.Create(fname)
112112
if err == nil {
113-
symlink := path.Join(dir, link)
113+
symlink := filepath.Join(dir, link)
114114
os.Remove(symlink) // ignore err
115115
os.Symlink(fname, symlink) // ignore err
116116
return f, fname, nil

glog_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package glog
1919
import (
2020
"bytes"
2121
"fmt"
22+
"path/filepath"
2223
"runtime"
2324
"strings"
2425
"testing"
@@ -299,9 +300,7 @@ func TestLogBacktraceAt(t *testing.T) {
299300
if !ok {
300301
t.Fatal("could not get file:line")
301302
}
302-
if i := strings.LastIndex(file, "/"); i >= 0 {
303-
file = file[i+1:]
304-
}
303+
_, file = filepath.Split(file)
305304
infoLine = fmt.Sprintf("%s:%d", file, line+delta)
306305
err := logging.traceLocation.Set(infoLine)
307306
if err != nil {

0 commit comments

Comments
 (0)