Example #1
0
/*
UpdateFromDisk updates the hash and modtime to match the file on disk.
*/
func (s *staticinfo) updateFromDisk(path string) error {
	if !s.Directory {
		hash, err := shared.ContentHash(path)
		if err != nil {
			return err
		}
		s.Content = hash
	}
	stat, err := os.Lstat(path)
	if err != nil {
		return err
	}
	s.Modtime = stat.ModTime()
	return nil
}
Example #2
0
/*
createStaticInfo for the given file at the path with all values filled
accordingly.
*/
func createStaticInfo(path, selfpeerid string) (*staticinfo, error) {
	// fetch all values we'll need to store
	id, err := shared.NewIdentifier()
	if err != nil {
		return nil, err
	}
	stat, err := os.Lstat(path)
	if err != nil {
		return nil, err
	}
	hash := ""
	if !stat.IsDir() {
		hash, err = shared.ContentHash(path)
		if err != nil {
			return nil, err
		}
	}
	return &staticinfo{
		Identification: id,
		Version:        shared.CreateVersion(),
		Directory:      stat.IsDir(),
		Content:        hash,
		Modtime:        stat.ModTime()}, nil
}