This repository was archived by the owner on Jul 11, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +18
-15
lines changed Expand file tree Collapse file tree 2 files changed +18
-15
lines changed Original file line number Diff line number Diff line change 1
1
// 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.
3
3
//
4
4
// Use of this source code is governed by a BSD-style
5
5
// license that can be found in the LICENSE file.
@@ -12,7 +12,6 @@ import (
12
12
"io/ioutil"
13
13
"log"
14
14
"os"
15
- "os/user"
16
15
"path/filepath"
17
16
"runtime/pprof"
18
17
"sort"
@@ -260,19 +259,14 @@ func main() {
260
259
if stat != nil && ! stat .IsDir () && stat .Mode ().IsRegular () {
261
260
os .Remove (master )
262
261
return
263
- } else {
264
- log .Fatal ("Invalid index path " + master )
265
262
}
263
+ log .Fatal ("Invalid index path " + master )
266
264
}
267
265
268
266
if * exclude != "" {
269
267
var excludePath string
270
268
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 :])
276
270
} else {
277
271
excludePath = * exclude
278
272
}
Original file line number Diff line number Diff line change 1
1
// 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.
3
3
//
4
4
// Use of this source code is governed by a BSD-style
5
5
// license that can be found in the LICENSE file.
@@ -434,16 +434,25 @@ func (ix Index) Close() {
434
434
ix .data .f .Close ()
435
435
}
436
436
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
+
437
450
// File returns the name of the index file to use.
438
451
// It is either $CSEARCHINDEX or $HOME/.csearchindex.
439
452
func File () string {
440
453
f := os .Getenv ("CSEARCHINDEX" )
441
454
if f != "" {
442
455
return f
443
456
}
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" )
449
458
}
You can’t perform that action at this time.
0 commit comments