// EqualHashes builds the list of local hashes before
// checking if there is any that should be updated
EqualHashes builds the list of local hashes before
checking if there is any that should be updated
// EqualHashes builds the list of local hashes before // checking if there is any that should be updated
func (up *Updater) EqualHashes(files map[string]*file.File) bool {
	for _, f := range files {
		log.Println("Checking file for changes:", f.Path)
		if len(f.Bytes) == 0 && !f.ReplacedText {
			data, err := ioutil.ReadFile(f.OriginalPath)
			if err != nil {
				panic(err)
			}
			f.Bytes = data
		} else if len(f.Bytes) == 0 && f.ReplacedText && len(f.Data) > 0 {
			f.Data = strings.TrimPrefix(f.Data, `[]byte("`)
			f.Data = strings.TrimSuffix(f.Data, `")`)
			f.Data = strings.Replace(f.Data, "\\x", "", -1)
			var err error
			f.Bytes, err = hex.DecodeString(f.Data)
			if err != nil {
				log.Println("SHIT", err)
				return false
			}
			f.Data = ""
		}
		sha := sha256.New()
		if _, err := sha.Write(f.Bytes); err != nil {
			panic(err)
			return false
		}
		up.LocalHashes[f.Path] = hex.EncodeToString(sha.Sum(nil))
	}
	update := false
	for k := range up.LocalHashes {
		if !up.EqualHash(k) {
			up.ToUpdate = append(up.ToUpdate, k)
			update = true
		}
	}
	return !update
}
func ( up * Updater ) EqualHashes ( files map [ string ] * file . File ) bool { for _ , f := range files { log . Println ( " " , f . Path ) if len ( f . Bytes ) == 0 && ! f . ReplacedText { data , err := ioutil . ReadFile ( f . OriginalPath ) if err != nil { panic ( err ) } f . Bytes = data } else if len ( f . Bytes ) == 0 && f . ReplacedText && len ( f . Data ) > 0 { f . Data = strings . TrimPrefix ( f . Data , `[]byte("` ) f . Data = strings . TrimSuffix ( f . Data , `")` ) f . Data = strings . Replace ( f . Data , " \\ " , " " , - 1 ) var err error f . Bytes , err = hex . DecodeString ( f . Data ) if err != nil { log . Println ( " " , err ) return false } f . Data = " " } sha := sha256 . New ( ) if _ , err := sha . Write ( f . Bytes ) ; err != nil { panic ( err ) return false } up . LocalHashes [ f . Path ] = hex . EncodeToString ( sha . Sum ( nil ) ) } update := false for k := range up . LocalHashes { if ! up . EqualHash ( k ) { up . ToUpdate = append ( up . ToUpdate , k ) update = true } } return ! update }
EqualHashes builds the list of local hashes before
checking if there is any that should be updated
EqualHashes builds the list of local hashes before checking if there is any that should be updated
// removes the []byte("") from the string // when the data isn't in the Bytes variable // check if there is any file to update