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