1package filepathext
 2
 3import (
 4	"path/filepath"
 5	"runtime"
 6	"strings"
 7)
 8
 9// SmartJoin joins two paths, treating the second path as absolute if it is an
10// absolute path.
11func SmartJoin(one, two string) string {
12	if SmartIsAbs(two) {
13		return two
14	}
15	return filepath.Join(one, two)
16}
17
18// SmartIsAbs checks if a path is absolute, considering both OS-specific and
19// Unix-style paths.
20func SmartIsAbs(path string) bool {
21	switch runtime.GOOS {
22	case "windows":
23		return filepath.IsAbs(path) || strings.HasPrefix(filepath.ToSlash(path), "/")
24	default:
25		return filepath.IsAbs(path)
26	}
27}