Makefile, server entry point prototype, compareFiles function + other minor changes
This commit is contained in:
parent
2efb8c4130
commit
c1ccb61346
10 changed files with 139 additions and 56 deletions
|
|
@ -1,8 +1,36 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
//! Not implemented
|
||||
func CompareFiles(file1 File, file2 File) bool {
|
||||
return false
|
||||
// Panic if e contains an error
|
||||
func Check(e error) {
|
||||
if e != nil {
|
||||
panic("Check: A fatal error occured during execution -> " + e.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if files correspond
|
||||
func CompareFiles(file1 File, file2 File) bool {
|
||||
return file1.Metadata.Hash == file2.Metadata.Hash
|
||||
}
|
||||
|
||||
// Gets the sha256 hash of a file's content
|
||||
func GetHash(file File) ([]byte, error) {
|
||||
// init
|
||||
hasher := sha256.New()
|
||||
file_path := "" //TODO: missing
|
||||
// Open file
|
||||
f, err := os.Open(file_path)
|
||||
if err != nil { // Path error
|
||||
return nil, err
|
||||
}
|
||||
// Compute hash
|
||||
io.Copy(hasher, f)
|
||||
sum := hasher.Sum(nil)
|
||||
|
||||
return sum, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue