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