Browse Source

Add Variables.InstallDirs for accurately scanning system

Containing /bin, /etc, /lib, /lib64, /sbin, /usr
pull/1/head
Tovi Jaeschke-Rogers 4 years ago
parent
commit
d0f53fd27f
3 changed files with 43 additions and 28 deletions
  1. +33
    -25
      Client/Filesystem/HashFilesystem.go
  2. +8
    -2
      Client/Package/InstallPackage.go
  3. +2
    -1
      Variables/Variables.go

+ 33
- 25
Client/Filesystem/HashFilesystem.go View File

@ -2,6 +2,7 @@ package Filesystem
import (
"PackageManager/Client/Database"
"PackageManager/Variables"
"crypto/md5"
"fmt"
"io/ioutil"
@ -44,43 +45,50 @@ func UpdateFilesystemHash() error {
var (
fileHash string
rows []Database.FilesystemHashRow
dir string
e error
)
e = filepath.Walk(".", func(path string, info os.FileInfo, e error) error {
if e != nil {
return e
for _, dir = range Variables.InstallDirs {
_, e = os.Stat(dir)
if os.IsNotExist(e) {
continue
}
e = filepath.Walk(dir, func(path string, info os.FileInfo, e error) error {
if e != nil {
return e
}
// Ignore hidden files
if strings.HasPrefix(info.Name(), ".") || strings.HasPrefix(path, ".") {
return nil
}
// Ignore hidden files
if strings.HasPrefix(info.Name(), ".") || strings.HasPrefix(path, ".") {
return nil
}
// Ignore directories
if info.IsDir() {
return nil
}
// Ignore directories
if info.IsDir() {
return nil
}
fileHash, e = HashFile(path)
fileHash, e = HashFile(path)
if e != nil {
return e
}
if e != nil {
return e
}
rows = append(rows, Database.FilesystemHashRow{
Path: path,
Hash: fileHash,
UpdatedAt: info.ModTime(),
})
rows = append(rows, Database.FilesystemHashRow{
Path: path,
Hash: fileHash,
UpdatedAt: info.ModTime(),
})
// TODO: If len(rows) > x, update the db and clear out rows, and continue
// TODO: If len(rows) > x, update the db and clear out rows, and continue
return nil
})
return nil
})
if e != nil {
panic(e)
if e != nil {
panic(e)
}
}
return Database.FindOrCreateFileHash(rows)


+ 8
- 2
Client/Package/InstallPackage.go View File

@ -23,9 +23,15 @@ func InstallPackage(pkgs []string) error {
}
for _, pkg = range pkgs {
fmt.Printf("Installing %s...", pkg)
fmt.Printf(
"Installing %s...\n",
pkg,
)
e = Archive.UntarGzip(pkg, Variables.DestDir)
fmt.Printf("%s successfully installed", pkg)
fmt.Printf(
"%s successfully installed\n",
pkg,
)
}
return nil


+ 2
- 1
Variables/Variables.go View File

@ -9,7 +9,8 @@ const (
)
var (
DestDir string = "/"
DestDir string = "/"
InstallDirs []string = []string{"/bin", "/etc", "/lib", "/lib64", "/sbin", "/usr"}
)
func init() {


Loading…
Cancel
Save