]> Sergey Matveev's repositories - glocate.git/blob - index.go
Raise copyright years
[glocate.git] / index.go
1 /*
2 glocate -- ZFS-diff-friendly locate-like utility
3 Copyright (C) 2022-2023 Sergey Matveev <stargrave@stargrave.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 package main
19
20 import (
21         "fmt"
22         "log"
23         "os"
24 )
25
26 func index() *os.File {
27         tmp0, err := os.CreateTemp(TmpDir, "glocate-idx")
28         if err != nil {
29                 log.Fatalln(err)
30         }
31         defer os.Remove(tmp0.Name())
32
33         entsWalker := make(chan Ent, 1<<10)
34         entsWriter := make(chan Ent, 1<<10)
35         dirSizerJob := make(chan struct{})
36         var dirSizes []int64
37         entsWalker <- Ent{name: []string{"./"}}
38         sinkBack := make(chan Ent, 1)
39         go func() {
40                 dirSizer(&dirSizes, 1, sinkBack, entsWalker, entsWriter)
41                 close(dirSizerJob)
42         }()
43
44         writerJob := make(chan struct{})
45         go func() {
46                 writer(tmp0, entsWriter)
47                 close(writerJob)
48         }()
49
50         walkerStatusStop := make(chan struct{})
51         go walkerStatus(walkerStatusStop)
52         err = walker(entsWalker, []string{"./"})
53         walkerStatusStop <- struct{}{}
54         <-walkerStatusStop
55         fmt.Print("\r")
56         if err != nil {
57                 log.Fatalln(err)
58         }
59         close(entsWalker)
60         <-dirSizerJob
61         close(entsWriter)
62         <-writerJob
63
64         tmp1 := applyDirSizes(tmp0, dirSizes)
65         tmp0.Close()
66         return tmp1
67 }