|
|
@ -1,15 +1,18 @@ |
|
|
|
package Filesystem |
|
|
|
|
|
|
|
import ( |
|
|
|
"PackageManager/Client/Database" |
|
|
|
"PackageManager/Color" |
|
|
|
"PackageManager/Variables" |
|
|
|
"fmt" |
|
|
|
"log" |
|
|
|
"os" |
|
|
|
"path/filepath" |
|
|
|
|
|
|
|
"github.com/vbauerster/mpb" |
|
|
|
"github.com/zenthangplus/goccm" |
|
|
|
bolt "go.etcd.io/bbolt" |
|
|
|
|
|
|
|
"PackageManager/Client/Database" |
|
|
|
"PackageManager/Client/ProgressBar" |
|
|
|
"PackageManager/Color" |
|
|
|
"PackageManager/Variables" |
|
|
|
) |
|
|
|
|
|
|
|
type FilesystemStatus struct { |
|
|
@ -66,7 +69,6 @@ func GetFilesystemLength(root string) (int, error) { |
|
|
|
|
|
|
|
// Ignore path in Variables.PruneRegexPaths
|
|
|
|
if i.IsDir() && matchAny(p, PruneRegex) { |
|
|
|
log.Println("Prune", p) |
|
|
|
return filepath.SkipDir |
|
|
|
} |
|
|
|
|
|
|
@ -87,6 +89,51 @@ 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) { |
|
|
|
var ( |
|
|
|
newFileObject FileObject |
|
|
|
knownFileObject FileObject |
|
|
|
pick, known []byte |
|
|
|
e error |
|
|
|
) |
|
|
|
|
|
|
|
defer func() { |
|
|
|
bar.Increment() |
|
|
|
c.Done() |
|
|
|
}() |
|
|
|
|
|
|
|
pick = picksBucket.Get([]byte(p)) |
|
|
|
known = indexBucket.Get([]byte(p)) |
|
|
|
|
|
|
|
if pick != nil { |
|
|
|
fsStatus.PickedFiles = append(fsStatus.PickedFiles, p) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if known != nil { |
|
|
|
newFileObject, e = CreateFileObject(p) |
|
|
|
if e != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
knownFileObject, e = FromBytes(known) |
|
|
|
if e != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
e = newFileObject.IsDifferent(knownFileObject) |
|
|
|
if e != nil { |
|
|
|
fsStatus.ModifiedFiles = append(fsStatus.ModifiedFiles, p) |
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
fsStatus.NewFiles = append(fsStatus.NewFiles, p) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
|
var ( |
|
|
|
fsStatus FilesystemStatus = FilesystemStatus{} |
|
|
@ -96,10 +143,11 @@ func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
|
picksBucket *bolt.Bucket |
|
|
|
indexBucket *bolt.Bucket |
|
|
|
|
|
|
|
pick, known []byte |
|
|
|
bar *mpb.Bar |
|
|
|
|
|
|
|
newFileObject FileObject |
|
|
|
knownFileObject FileObject |
|
|
|
fsCount int |
|
|
|
|
|
|
|
c goccm.ConcurrencyManager |
|
|
|
|
|
|
|
e error |
|
|
|
) |
|
|
@ -113,6 +161,13 @@ func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
|
root = root + "/" |
|
|
|
} |
|
|
|
|
|
|
|
fsCount, e = GetFilesystemLength(root) |
|
|
|
if e != nil { |
|
|
|
return fsStatus, e |
|
|
|
} |
|
|
|
|
|
|
|
bar = ProgressBar.InitBar("Scanning...", fsCount) |
|
|
|
|
|
|
|
e = Database.FsDB.View(func(tx *bolt.Tx) error { |
|
|
|
|
|
|
|
picksBucket = tx.Bucket(Variables.FsHashPicksBucket) |
|
|
@ -122,7 +177,6 @@ func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
|
|
|
|
|
// Ignore path in Variables.PruneRegexPaths
|
|
|
|
if i.IsDir() && matchAny(p, PruneRegex) { |
|
|
|
log.Println("Prune", p) |
|
|
|
return filepath.SkipDir |
|
|
|
} |
|
|
|
|
|
|
@ -135,37 +189,7 @@ func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
pick = picksBucket.Get([]byte(p)) |
|
|
|
known = indexBucket.Get([]byte(p)) |
|
|
|
|
|
|
|
if pick != nil { |
|
|
|
fsStatus.PickedFiles = append(fsStatus.PickedFiles, p) |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
if known != nil { |
|
|
|
newFileObject, e = CreateFileObject(p) |
|
|
|
if os.IsNotExist(e) { |
|
|
|
return nil |
|
|
|
} |
|
|
|
if e != nil { |
|
|
|
return e |
|
|
|
} |
|
|
|
|
|
|
|
knownFileObject, e = FromBytes(known) |
|
|
|
if e != nil { |
|
|
|
return e |
|
|
|
} |
|
|
|
|
|
|
|
e = newFileObject.IsDifferent(knownFileObject) |
|
|
|
if e != nil { |
|
|
|
fsStatus.ModifiedFiles = append(fsStatus.ModifiedFiles, p) |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
fsStatus.NewFiles = append(fsStatus.NewFiles, p) |
|
|
|
go fsStatus.parseFile(indexBucket, picksBucket, p, bar, c) |
|
|
|
|
|
|
|
return nil |
|
|
|
}) |
|
|
@ -178,6 +202,8 @@ func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
|
return nil |
|
|
|
}) |
|
|
|
|
|
|
|
ProgressBar.CloseBar(bar) |
|
|
|
|
|
|
|
return nil |
|
|
|
}) |
|
|
|
|
|
|
|