Do not save empty files, use origin rather than filename for error message

This commit is contained in:
maride 2023-09-02 17:30:35 +02:00
parent 2f44d92262
commit 112c027950

View File

@ -20,12 +20,18 @@ var (
// This means that a module should _always_ call this function when a file is encountered. // This means that a module should _always_ call this function when a file is encountered.
// origin is a descriptive string where the file comes from, e.g. the module name. // origin is a descriptive string where the file comes from, e.g. the module name.
func RegisterFile(filename string, content []byte, origin string) { func RegisterFile(filename string, content []byte, origin string) {
// Check if there even is anything to register
if len(content) == 0 {
// File is empty, won't register the void
log.Printf("Avoided registering file from %s because it is empty.", origin)
return
}
thisFile := NewFile(filename, content, origin) thisFile := NewFile(filename, content, origin)
// To avoid doubles, we need to check if that hash is already present // To avoid doubles, we need to check if that hash is already present
for _, f := range registeredFiles { for _, f := range registeredFiles {
if f.hash == thisFile.hash { if f.hash == thisFile.hash {
// Found - stop here // Found - stop here
log.Printf("Avoided registering file '%s' because it has the same content as an already registered file ", f.name) log.Printf("Avoided registering file from %s because it has the same content as an already registered file ", origin)
return return
} }
} }