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

Commit

Permalink
Relax cgo dependency (os/user) to enable cross platform goxc builds t…
Browse files Browse the repository at this point in the history
…o work
  • Loading branch information
junkblocker committed Nov 18, 2014
1 parent 7c13459 commit 03a7df6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
12 changes: 3 additions & 9 deletions cmd/cindex/cindex.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2011 The Go Authors. All rights reserved.
// Copyright 2013 Manpreet Singh ( junkblocker@yahoo.com ). All rights reserved.
// Copyright 2013-2014 Manpreet Singh ( junkblocker@yahoo.com ). All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
Expand All @@ -12,7 +12,6 @@ import (
"io/ioutil"
"log"
"os"
"os/user"
"path/filepath"
"runtime/pprof"
"sort"
Expand Down Expand Up @@ -260,19 +259,14 @@ func main() {
if stat != nil && !stat.IsDir() && stat.Mode().IsRegular() {
os.Remove(master)
return
} else {
log.Fatal("Invalid index path " + master)
}
log.Fatal("Invalid index path " + master)
}

if *exclude != "" {
var excludePath string
if (*exclude)[:2] == "~/" {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
excludePath = filepath.Join(usr.HomeDir, (*exclude)[2:])
excludePath = filepath.Join(index.HomeDir(), (*exclude)[2:])
} else {
excludePath = *exclude
}
Expand Down
21 changes: 15 additions & 6 deletions index/read.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2011 The Go Authors. All rights reserved.
// Copyright 2013 Manpreet Singh ( junkblocker@yahoo.com ). All rights reserved.
// Copyright 2013-2014 Manpreet Singh ( junkblocker@yahoo.com ). All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
Expand Down Expand Up @@ -434,16 +434,25 @@ func (ix Index) Close() {
ix.data.f.Close()
}

// find home directory without cgo if needed
func HomeDir() string {
u, err := user.Current()
if err != nil {
h := os.Getenv("HOME")
if h == "" {
log.Fatal("Could not determine home directory")
}
return h
}
return u.HomeDir
}

// File returns the name of the index file to use.
// It is either $CSEARCHINDEX or $HOME/.csearchindex.
func File() string {
f := os.Getenv("CSEARCHINDEX")
if f != "" {
return f
}
u, err := user.Current()
if err != nil {
log.Fatal(err)
}
return filepath.Join(u.HomeDir, ".csearchindex")
return filepath.Join(HomeDir(), ".csearchindex")
}

0 comments on commit 03a7df6

Please sign in to comment.