|
@ -2,6 +2,7 @@ package Filesystem |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"PackageManager/Client/Database" |
|
|
"PackageManager/Client/Database" |
|
|
|
|
|
"PackageManager/Color" |
|
|
"PackageManager/Variables" |
|
|
"PackageManager/Variables" |
|
|
"fmt" |
|
|
"fmt" |
|
|
"log" |
|
|
"log" |
|
@ -30,47 +31,60 @@ func ShowFilesystemDiff(root string) error { |
|
|
return e |
|
|
return e |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if len(fsStatus.NewFiles) > 0 { |
|
|
|
|
|
fmt.Printf("New files: %d\n", len(fsStatus.NewFiles)) |
|
|
|
|
|
/* |
|
|
|
|
|
fmt.Println("New files:") |
|
|
|
|
|
for _, f = range fsStatus.NewFiles { |
|
|
|
|
|
fmt.Printf("\t%s\n", Color.Green(f)) |
|
|
|
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
fmt.Println("New files:") |
|
|
|
|
|
PrintFilesOrLength(fsStatus.NewFiles, Color.Green) |
|
|
|
|
|
|
|
|
if len(fsStatus.PickedFiles) > 0 { |
|
|
|
|
|
fmt.Printf("Picked files: %d\n", len(fsStatus.PickedFiles)) |
|
|
|
|
|
/* |
|
|
|
|
|
fmt.Println("Added files:") |
|
|
|
|
|
for _, f = range fsStatus.PickedFiles { |
|
|
|
|
|
fmt.Printf("\t%s\n", Color.Green(f)) |
|
|
|
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
fmt.Println("Added files:") |
|
|
|
|
|
PrintFilesOrLength(fsStatus.PickedFiles, Color.Green) |
|
|
|
|
|
|
|
|
if len(fsStatus.ModifiedFiles) > 0 { |
|
|
|
|
|
fmt.Printf("Modified files: %d\n", len(fsStatus.ModifiedFiles)) |
|
|
|
|
|
/* |
|
|
|
|
|
fmt.Println("Modified files:") |
|
|
|
|
|
for _, f = range fsStatus.ModifiedFiles { |
|
|
|
|
|
fmt.Printf("\t%s\n", Color.Green(f)) |
|
|
|
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
fmt.Println("Modified files:") |
|
|
|
|
|
PrintFilesOrLength(fsStatus.ModifiedFiles, Color.Warning) |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("Deleted files:") |
|
|
|
|
|
PrintFilesOrLength(fsStatus.MissingFiles, Color.Fatal) |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetFilesystemLength(root string) (int, error) { |
|
|
|
|
|
var ( |
|
|
|
|
|
rootStat os.FileInfo |
|
|
|
|
|
fsCount int = 0 |
|
|
|
|
|
e error |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
rootStat, e = os.Stat(root) |
|
|
|
|
|
if e != nil { |
|
|
|
|
|
return fsCount, e |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if len(fsStatus.MissingFiles) > 0 { |
|
|
|
|
|
fmt.Printf("Modified files: %d\n", len(fsStatus.MissingFiles)) |
|
|
|
|
|
/* |
|
|
|
|
|
fmt.Println("Deleted files:") |
|
|
|
|
|
for _, f = range fsStatus.MissingFiles { |
|
|
|
|
|
fmt.Printf("\t%s\n", Color.Green(f)) |
|
|
|
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
if rootStat.IsDir() && root[len(root)-1:] != "/" { |
|
|
|
|
|
root = root + "/" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
|
filepath.Walk(root, func(p string, i os.FileInfo, _ error) error { |
|
|
|
|
|
|
|
|
|
|
|
// Ignore path in Variables.PruneRegexPaths
|
|
|
|
|
|
if i.IsDir() && matchAny(p, PruneRegex) { |
|
|
|
|
|
log.Println("Prune", p) |
|
|
|
|
|
return filepath.SkipDir |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Ignore path in Variables.IgnoreRegexPaths
|
|
|
|
|
|
if matchAny(p, IgnoreRegex) { |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !i.Mode().IsRegular() && (i.Mode()&os.ModeSymlink == 0) { |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fsCount++ |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return fsCount, e |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
@ -102,7 +116,7 @@ func GetFilesystemDiff(root string) (FilesystemStatus, error) { |
|
|
e = Database.FsDB.View(func(tx *bolt.Tx) error { |
|
|
e = Database.FsDB.View(func(tx *bolt.Tx) error { |
|
|
|
|
|
|
|
|
picksBucket = tx.Bucket(Variables.FsHashPicksBucket) |
|
|
picksBucket = tx.Bucket(Variables.FsHashPicksBucket) |
|
|
indexBucket = tx.Bucket(Variables.FsHashPicksBucket) |
|
|
|
|
|
|
|
|
indexBucket = tx.Bucket(Variables.FsHashIndexBucket) |
|
|
|
|
|
|
|
|
filepath.Walk(root, func(p string, i os.FileInfo, _ error) error { |
|
|
filepath.Walk(root, func(p string, i os.FileInfo, _ error) error { |
|
|
|
|
|
|
|
|