|
|
@ -1,13 +1,15 @@ |
|
|
|
package Filesystem |
|
|
|
|
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"fmt" |
|
|
|
"os" |
|
|
|
"path/filepath" |
|
|
|
"runtime" |
|
|
|
|
|
|
|
"github.com/vbauerster/mpb" |
|
|
|
"github.com/zenthangplus/goccm" |
|
|
|
bolt "go.etcd.io/bbolt" |
|
|
|
"golang.org/x/sync/semaphore" |
|
|
|
|
|
|
|
"PackageManager/Client/Database" |
|
|
|
"PackageManager/Client/ProgressBar" |
|
|
@ -89,7 +91,7 @@ func GetFilesystemLength(root string) (int, error) { |
|
|
|
return fsCount, e |
|
|
|
} |
|
|
|
|
|
|
|
func (fsStatus *FilesystemStatus) parseFile(indexBucket, picksBucket *bolt.Bucket, p string, bar *mpb.Bar, c goccm.ConcurrencyManager) { |
|
|
|
func (fsStatus *FilesystemStatus) parseFile(indexBucket, picksBucket *bolt.Bucket, p string, bar *mpb.Bar) { |
|
|
|
var ( |
|
|
|
newFileObject FileObject |
|
|
|
knownFileObject FileObject |
|
|
@ -99,7 +101,6 @@ func (fsStatus *FilesystemStatus) parseFile(indexBucket, picksBucket *bolt.Bucke |
|
|
|
|
|
|
|
defer func() { |
|
|
|
bar.Increment() |
|
|
|
c.Done() |
|
|
|
}() |
|
|
|
|
|
|
|
pick = picksBucket.Get([]byte(p)) |
|
|
@ -136,22 +137,20 @@ func (fsStatus *FilesystemStatus) parseFile(indexBucket, picksBucket *bolt.Bucke |
|
|
|
|
|
|
|
func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
|
var ( |
|
|
|
fsStatus FilesystemStatus = FilesystemStatus{} |
|
|
|
|
|
|
|
rootStat os.FileInfo |
|
|
|
|
|
|
|
fsStatus FilesystemStatus = FilesystemStatus{} |
|
|
|
sem *semaphore.Weighted |
|
|
|
picksBucket *bolt.Bucket |
|
|
|
indexBucket *bolt.Bucket |
|
|
|
|
|
|
|
bar *mpb.Bar |
|
|
|
|
|
|
|
fsCount int |
|
|
|
|
|
|
|
c goccm.ConcurrencyManager |
|
|
|
|
|
|
|
e error |
|
|
|
rootStat os.FileInfo |
|
|
|
bar *mpb.Bar |
|
|
|
fsCount int |
|
|
|
poolSize int |
|
|
|
e error |
|
|
|
) |
|
|
|
|
|
|
|
poolSize = runtime.NumCPU() |
|
|
|
sem = semaphore.NewWeighted(int64(poolSize)) |
|
|
|
|
|
|
|
rootStat, e = os.Stat(root) |
|
|
|
if e != nil { |
|
|
|
return fsStatus, e |
|
|
@ -189,7 +188,13 @@ func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
go fsStatus.parseFile(indexBucket, picksBucket, p, bar, c) |
|
|
|
Variables.WG.Add(1) |
|
|
|
sem.Acquire(context.Background(), 1) |
|
|
|
go func() { |
|
|
|
fsStatus.parseFile(indexBucket, picksBucket, p, bar) |
|
|
|
Variables.WG.Done() |
|
|
|
sem.Release(1) |
|
|
|
}() |
|
|
|
|
|
|
|
return nil |
|
|
|
}) |
|
|
@ -202,6 +207,7 @@ func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
|
return nil |
|
|
|
}) |
|
|
|
|
|
|
|
Variables.WG.Wait() |
|
|
|
ProgressBar.CloseBar(bar) |
|
|
|
|
|
|
|
return nil |
|
|
|