|
|
@ -35,21 +35,24 @@ func ShowFilesystemDiff(root string) error { |
|
|
|
fsStatus FilesystemStatus |
|
|
|
picksBucket *bolt.Bucket |
|
|
|
pickedFiles []string |
|
|
|
e error |
|
|
|
err error |
|
|
|
) |
|
|
|
|
|
|
|
fsStatus, e = GetFilesystemDiff(root) |
|
|
|
if e != nil { |
|
|
|
return e |
|
|
|
fsStatus, err = GetFilesystemDiff(root) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
e = Database.FsDB.View(func(tx *bolt.Tx) error { |
|
|
|
err = Database.FsDB.View(func(tx *bolt.Tx) error { |
|
|
|
picksBucket = tx.Bucket(Variables.FsHashPicksBucket) |
|
|
|
return picksBucket.ForEach(func(key, _ []byte) error { |
|
|
|
pickedFiles = append(pickedFiles, string(key)) |
|
|
|
return nil |
|
|
|
}) |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
fmt.Println("New files:") |
|
|
|
PrintFilesOrLength(fsStatus.NewFiles, Color.Green) |
|
|
@ -70,19 +73,19 @@ func GetFilesystemLength(root string) (int, error) { |
|
|
|
var ( |
|
|
|
rootStat os.FileInfo |
|
|
|
fsCount int = 0 |
|
|
|
e error |
|
|
|
err error |
|
|
|
) |
|
|
|
|
|
|
|
rootStat, e = os.Stat(root) |
|
|
|
if e != nil { |
|
|
|
return fsCount, e |
|
|
|
rootStat, err = os.Stat(root) |
|
|
|
if err != nil { |
|
|
|
return fsCount, err |
|
|
|
} |
|
|
|
|
|
|
|
if rootStat.IsDir() && root[len(root)-1:] != "/" { |
|
|
|
root = root + "/" |
|
|
|
} |
|
|
|
|
|
|
|
filepath.Walk(root, func(p string, i os.FileInfo, _ error) error { |
|
|
|
err = filepath.Walk(root, func(p string, i os.FileInfo, _ error) error { |
|
|
|
|
|
|
|
// Ignore path in Variables.PruneRegexPaths
|
|
|
|
if i.IsDir() && matchAny(p, PruneRegex) { |
|
|
@ -103,7 +106,7 @@ func GetFilesystemLength(root string) (int, error) { |
|
|
|
return nil |
|
|
|
}) |
|
|
|
|
|
|
|
return fsCount, e |
|
|
|
return fsCount, err |
|
|
|
} |
|
|
|
|
|
|
|
func (fsStatus *FilesystemStatus) parseFile(indexBucket, picksBucket *bolt.Bucket, p string, bar *mpb.Bar) { |
|
|
@ -111,7 +114,7 @@ func (fsStatus *FilesystemStatus) parseFile(indexBucket, picksBucket *bolt.Bucke |
|
|
|
newFileObject FileObject |
|
|
|
knownFileObject FileObject |
|
|
|
pick, known []byte |
|
|
|
e error |
|
|
|
err error |
|
|
|
) |
|
|
|
|
|
|
|
defer func() { |
|
|
@ -130,18 +133,18 @@ func (fsStatus *FilesystemStatus) parseFile(indexBucket, picksBucket *bolt.Bucke |
|
|
|
} |
|
|
|
|
|
|
|
if known != nil { |
|
|
|
newFileObject, e = CreateFileObject(p) |
|
|
|
if e != nil { |
|
|
|
newFileObject, err = CreateFileObject(p) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
knownFileObject, e = FromBytes(known) |
|
|
|
if e != nil { |
|
|
|
knownFileObject, err = FromBytes(known) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
e = newFileObject.IsDifferent(knownFileObject) |
|
|
|
if e != nil { |
|
|
|
err = newFileObject.IsDifferent(knownFileObject) |
|
|
|
if err != nil { |
|
|
|
fsStatusWG.Wait() |
|
|
|
fsStatusWG.Add(1) |
|
|
|
fsStatus.ModifiedFiles = append(fsStatus.ModifiedFiles, p) |
|
|
@ -155,8 +158,6 @@ func (fsStatus *FilesystemStatus) parseFile(indexBucket, picksBucket *bolt.Bucke |
|
|
|
fsStatusWG.Add(1) |
|
|
|
fsStatus.NewFiles = append(fsStatus.NewFiles, p) |
|
|
|
fsStatusWG.Done() |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
@ -169,29 +170,29 @@ func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
|
bar *mpb.Bar |
|
|
|
fsCount int |
|
|
|
poolSize int |
|
|
|
e error |
|
|
|
err error |
|
|
|
) |
|
|
|
|
|
|
|
poolSize = runtime.NumCPU() |
|
|
|
sem = semaphore.NewWeighted(int64(poolSize)) |
|
|
|
|
|
|
|
rootStat, e = os.Stat(root) |
|
|
|
if e != nil { |
|
|
|
return fsStatus, e |
|
|
|
rootStat, err = os.Stat(root) |
|
|
|
if err != nil { |
|
|
|
return fsStatus, err |
|
|
|
} |
|
|
|
|
|
|
|
if rootStat.IsDir() && root[len(root)-1:] != "/" { |
|
|
|
root = root + "/" |
|
|
|
} |
|
|
|
|
|
|
|
fsCount, e = GetFilesystemLength(root) |
|
|
|
if e != nil { |
|
|
|
return fsStatus, e |
|
|
|
fsCount, err = GetFilesystemLength(root) |
|
|
|
if err != nil { |
|
|
|
return fsStatus, err |
|
|
|
} |
|
|
|
|
|
|
|
bar = ProgressBar.InitBar("Scanning...", fsCount) |
|
|
|
|
|
|
|
e = Database.FsDB.View(func(tx *bolt.Tx) error { |
|
|
|
err = Database.FsDB.View(func(tx *bolt.Tx) error { |
|
|
|
|
|
|
|
picksBucket = tx.Bucket(Variables.FsHashPicksBucket) |
|
|
|
indexBucket = tx.Bucket(Variables.FsHashIndexBucket) |
|
|
@ -225,8 +226,8 @@ func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
|
}) |
|
|
|
|
|
|
|
indexBucket.ForEach(func(k, v []byte) error { |
|
|
|
_, e = os.Lstat(string(k)) |
|
|
|
if os.IsNotExist(e) { |
|
|
|
_, err = os.Lstat(string(k)) |
|
|
|
if os.IsNotExist(err) { |
|
|
|
fsStatus.MissingFiles = append(fsStatus.MissingFiles, string(k)) |
|
|
|
} |
|
|
|
return nil |
|
|
@ -235,5 +236,5 @@ func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
|
return nil |
|
|
|
}) |
|
|
|
|
|
|
|
return fsStatus, e |
|
|
|
return fsStatus, err |
|
|
|
} |