|
@ -2,6 +2,7 @@ package Filesystem |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"PackageManager/Client/Database" |
|
|
"PackageManager/Client/Database" |
|
|
|
|
|
"PackageManager/Variables" |
|
|
"crypto/md5" |
|
|
"crypto/md5" |
|
|
"fmt" |
|
|
"fmt" |
|
|
"io/ioutil" |
|
|
"io/ioutil" |
|
@ -44,43 +45,50 @@ func UpdateFilesystemHash() error { |
|
|
var ( |
|
|
var ( |
|
|
fileHash string |
|
|
fileHash string |
|
|
rows []Database.FilesystemHashRow |
|
|
rows []Database.FilesystemHashRow |
|
|
|
|
|
dir string |
|
|
e error |
|
|
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) |
|
|
return Database.FindOrCreateFileHash(rows) |
|
|