Skip to content
This repository was archived by the owner on Jul 11, 2022. It is now read-only.

Commit 03a7df6

Browse files
committed
Relax cgo dependency (os/user) to enable cross platform goxc builds to work
1 parent 7c13459 commit 03a7df6

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

cmd/cindex/cindex.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2011 The Go Authors. All rights reserved.
2-
// Copyright 2013 Manpreet Singh ( junkblocker@yahoo.com ). All rights reserved.
2+
// Copyright 2013-2014 Manpreet Singh ( junkblocker@yahoo.com ). All rights reserved.
33
//
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
@@ -12,7 +12,6 @@ import (
1212
"io/ioutil"
1313
"log"
1414
"os"
15-
"os/user"
1615
"path/filepath"
1716
"runtime/pprof"
1817
"sort"
@@ -260,19 +259,14 @@ func main() {
260259
if stat != nil && !stat.IsDir() && stat.Mode().IsRegular() {
261260
os.Remove(master)
262261
return
263-
} else {
264-
log.Fatal("Invalid index path " + master)
265262
}
263+
log.Fatal("Invalid index path " + master)
266264
}
267265

268266
if *exclude != "" {
269267
var excludePath string
270268
if (*exclude)[:2] == "~/" {
271-
usr, err := user.Current()
272-
if err != nil {
273-
log.Fatal(err)
274-
}
275-
excludePath = filepath.Join(usr.HomeDir, (*exclude)[2:])
269+
excludePath = filepath.Join(index.HomeDir(), (*exclude)[2:])
276270
} else {
277271
excludePath = *exclude
278272
}

index/read.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2011 The Go Authors. All rights reserved.
2-
// Copyright 2013 Manpreet Singh ( junkblocker@yahoo.com ). All rights reserved.
2+
// Copyright 2013-2014 Manpreet Singh ( junkblocker@yahoo.com ). All rights reserved.
33
//
44
// Use of this source code is governed by a BSD-style
55
// license that can be found in the LICENSE file.
@@ -434,16 +434,25 @@ func (ix Index) Close() {
434434
ix.data.f.Close()
435435
}
436436

437+
// find home directory without cgo if needed
438+
func HomeDir() string {
439+
u, err := user.Current()
440+
if err != nil {
441+
h := os.Getenv("HOME")
442+
if h == "" {
443+
log.Fatal("Could not determine home directory")
444+
}
445+
return h
446+
}
447+
return u.HomeDir
448+
}
449+
437450
// File returns the name of the index file to use.
438451
// It is either $CSEARCHINDEX or $HOME/.csearchindex.
439452
func File() string {
440453
f := os.Getenv("CSEARCHINDEX")
441454
if f != "" {
442455
return f
443456
}
444-
u, err := user.Current()
445-
if err != nil {
446-
log.Fatal(err)
447-
}
448-
return filepath.Join(u.HomeDir, ".csearchindex")
457+
return filepath.Join(HomeDir(), ".csearchindex")
449458
}

0 commit comments

Comments
 (0)