This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relax cgo dependency (os/user) to enable cross platform goxc builds t…
…o work
- Loading branch information
1 parent
7c13459
commit 03a7df6
Showing
2 changed files
with
18 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ( [email protected] ). All rights reserved. | ||
// Copyright 2013-2014 Manpreet Singh ( [email protected] ). All rights reserved. | ||
// | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
@@ -12,7 +12,6 @@ import ( | |
"io/ioutil" | ||
"log" | ||
"os" | ||
"os/user" | ||
"path/filepath" | ||
"runtime/pprof" | ||
"sort" | ||
|
@@ -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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ( [email protected] ). All rights reserved. | ||
// Copyright 2013-2014 Manpreet Singh ( [email protected] ). All rights reserved. | ||
// | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
@@ -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") | ||
} |