diff options
| author | Shulhan <ms@kilabit.info> | 2018-05-21 03:52:13 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2018-05-21 03:52:13 +0700 |
| commit | 07793357af399c3f6722be3d1f5efb7af4e432b4 (patch) | |
| tree | 55771f734c63292be20a9f18e2fdd3933e1d58dc | |
| parent | 8f01bf679c2bec9b514f4ea2d0f3d5c4eca9e953 (diff) | |
| download | beku-07793357af399c3f6722be3d1f5efb7af4e432b4.tar.xz | |
Use filepath.Join when applicable
| -rw-r--r-- | beku.go | 2 | ||||
| -rw-r--r-- | env.go | 20 | ||||
| -rw-r--r-- | package.go | 3 | ||||
| -rw-r--r-- | package_git.go | 5 | ||||
| -rw-r--r-- | package_test.go | 18 |
5 files changed, 25 insertions, 23 deletions
@@ -17,7 +17,7 @@ const ( dbgSkipSelf = "skip self dep" dbgSkipStd = "skip std dep" - dirDB = "/var/beku" + dirDB = "var/beku" dirBin = "bin" dirPkg = "pkg" dirSrc = "src" @@ -55,12 +55,12 @@ func NewEnvironment() (env *Env, err error) { Debug = debugMode(debug) env = &Env{ - dirSrc: build.Default.GOPATH + "/" + dirSrc, - dirRootSrc: build.Default.GOROOT + "/" + dirSrc, - dirBin: build.Default.GOPATH + "/" + dirBin, - dirPkg: build.Default.GOPATH + "/" + dirPkg + "/" + - build.Default.GOOS + "_" + build.Default.GOARCH, - dbDefFile: build.Default.GOPATH + dirDB + "/" + DefDBName, + dirSrc: filepath.Join(build.Default.GOPATH, dirSrc), + dirRootSrc: filepath.Join(build.Default.GOROOT, dirSrc), + dirBin: filepath.Join(build.Default.GOPATH, dirBin), + dirPkg: filepath.Join(build.Default.GOPATH, dirPkg, + build.Default.GOOS+"_"+build.Default.GOARCH), + dbDefFile: filepath.Join(build.Default.GOPATH, dirDB, DefDBName), } err = env.scanStdPackages(env.dirRootSrc) @@ -133,7 +133,7 @@ func (env *Env) scanStdPackages(srcPath string) error { } dirName := fi.Name() - fullPath := srcPath + "/" + dirName + fullPath := filepath.Join(srcPath, dirName) // (1) if IsIgnoredDir(dirName) { @@ -175,8 +175,8 @@ func (env *Env) scanPackages(rootPath string) (err error) { } dirName := fi.Name() - fullPath := rootPath + "/" + dirName - dirGit := fullPath + "/" + gitDir + fullPath := filepath.Join(rootPath, dirName) + dirGit := filepath.Join(fullPath, gitDir) // (1) if IsIgnoredDir(dirName) { @@ -284,7 +284,7 @@ func (env *Env) Load(file string) (err error) { pkg := &Package{ ImportPath: sec.Sub, - FullPath: env.dirSrc + "/" + sec.Sub, + FullPath: filepath.Join(env.dirSrc, sec.Sub), } pkg.load(sec) @@ -11,6 +11,7 @@ import ( "log" "os" "os/exec" + "path/filepath" "sort" "strings" @@ -44,7 +45,7 @@ func NewPackage(pkgName, importPath string, vcsMode VCSMode) ( pkg = &Package{ ImportPath: importPath, RemoteURL: "https://" + pkgName, - FullPath: build.Default.GOPATH + "/" + dirSrc + "/" + importPath, + FullPath: filepath.Join(build.Default.GOPATH, dirSrc, importPath), vcs: vcsMode, } diff --git a/package_git.go b/package_git.go index ee46d39..8f43b47 100644 --- a/package_git.go +++ b/package_git.go @@ -6,6 +6,7 @@ import ( "log" "os" "os/exec" + "path/filepath" "github.com/shuLhan/share/lib/ini" ) @@ -105,7 +106,7 @@ func (pkg *Package) gitFetch() (err error) { if pkg.isTag { pkg.VersionNext, err = pkg.gitGetTagLatest() } else { - ref := pkg.RemoteName + "/" + gitDefBranch + ref := filepath.Join(pkg.RemoteName, gitDefBranch) pkg.VersionNext, err = pkg.gitGetCommit(ref) } @@ -267,7 +268,7 @@ func (pkg *Package) gitScan() (err error) { } func (pkg *Package) gitScanRemote() (err error) { - gitConfig := pkg.FullPath + "/" + gitDir + "/config" + gitConfig := filepath.Join(pkg.FullPath, gitDir, "config") gitIni, err := ini.Open(gitConfig) if err != nil { diff --git a/package_test.go b/package_test.go index 993e5a9..611dec5 100644 --- a/package_test.go +++ b/package_test.go @@ -530,21 +530,21 @@ func testUpdate(t *testing.T) { curPkg: &Package{ vcs: VCSModeGit, ImportPath: testGitRepo, - FullPath: testEnv.dirSrc + "/" + testGitRepo, + FullPath: filepath.Join(testEnv.dirSrc, testGitRepo), RemoteName: gitDefRemoteName, RemoteURL: "https://" + testGitRepo, }, newPkg: &Package{ vcs: VCSModeGit, ImportPath: testGitRepo, - FullPath: testEnv.dirSrc + "/" + testGitRepo, + FullPath: filepath.Join(testEnv.dirSrc, testGitRepo), RemoteName: gitDefRemoteName, RemoteURL: "git@github.com:shuLhan/beku_test.git", }, expPkg: &Package{ vcs: VCSModeGit, ImportPath: testGitRepo, - FullPath: testEnv.dirSrc + "/" + testGitRepo, + FullPath: filepath.Join(testEnv.dirSrc, testGitRepo), RemoteName: gitDefRemoteName, RemoteURL: "git@github.com:shuLhan/beku_test.git", }, @@ -553,14 +553,14 @@ func testUpdate(t *testing.T) { curPkg: &Package{ vcs: VCSModeGit, ImportPath: testGitRepo, - FullPath: testEnv.dirSrc + "/" + testGitRepo, + FullPath: filepath.Join(testEnv.dirSrc, testGitRepo), RemoteName: gitDefRemoteName, RemoteURL: "https://" + testGitRepo, }, newPkg: &Package{ vcs: VCSModeGit, ImportPath: testGitRepo, - FullPath: testEnv.dirSrc + "/" + testGitRepo, + FullPath: filepath.Join(testEnv.dirSrc, testGitRepo), RemoteName: gitDefRemoteName, RemoteURL: "git@github.com:shuLhan/beku_test.git", Version: "v0.1.0", @@ -569,7 +569,7 @@ func testUpdate(t *testing.T) { expPkg: &Package{ vcs: VCSModeGit, ImportPath: testGitRepo, - FullPath: testEnv.dirSrc + "/" + testGitRepo, + FullPath: filepath.Join(testEnv.dirSrc, testGitRepo), RemoteName: gitDefRemoteName, RemoteURL: "git@github.com:shuLhan/beku_test.git", Version: "v0.1.0", @@ -580,14 +580,14 @@ func testUpdate(t *testing.T) { curPkg: &Package{ vcs: VCSModeGit, ImportPath: testGitRepo, - FullPath: testEnv.dirSrc + "/" + testGitRepo, + FullPath: filepath.Join(testEnv.dirSrc, testGitRepo), RemoteName: gitDefRemoteName, RemoteURL: "https://" + testGitRepo, }, newPkg: &Package{ vcs: VCSModeGit, ImportPath: testGitRepo, - FullPath: testEnv.dirSrc + "/" + testGitRepo, + FullPath: filepath.Join(testEnv.dirSrc, testGitRepo), RemoteName: gitDefRemoteName, RemoteURL: "git@github.com:shuLhan/beku_test.git", Version: "c9f69fb", @@ -596,7 +596,7 @@ func testUpdate(t *testing.T) { expPkg: &Package{ vcs: VCSModeGit, ImportPath: testGitRepo, - FullPath: testEnv.dirSrc + "/" + testGitRepo, + FullPath: filepath.Join(testEnv.dirSrc, testGitRepo), RemoteName: gitDefRemoteName, RemoteURL: "git@github.com:shuLhan/beku_test.git", Version: "c9f69fb", |
