diff --git a/Client/Filesystem/HashFilesystem.go b/Client/Filesystem/HashFilesystem.go index 99f937b..2a00261 100644 --- a/Client/Filesystem/HashFilesystem.go +++ b/Client/Filesystem/HashFilesystem.go @@ -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) diff --git a/Client/Package/InstallPackage.go b/Client/Package/InstallPackage.go index 320f97f..f514594 100644 --- a/Client/Package/InstallPackage.go +++ b/Client/Package/InstallPackage.go @@ -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 diff --git a/Variables/Variables.go b/Variables/Variables.go index 3808ad0..f0959cf 100644 --- a/Variables/Variables.go +++ b/Variables/Variables.go @@ -9,7 +9,8 @@ const ( ) var ( - DestDir string = "/" + DestDir string = "/" + InstallDirs []string = []string{"/bin", "/etc", "/lib", "/lib64", "/sbin", "/usr"} ) func init() {