Ejemplo n.º 1
0
func installFile(sources []string, dst string, opt *install.InstallOption) {
	for _, src := range sources {
		if err := install.InstallFile(src, dst, opt); err != nil {
			fmt.Printf("error %s to %s: %s", src, dst, err)
			os.Exit(-1)
		}
	}
}
Ejemplo n.º 2
0
func (r *Rule) install(fi *FileInfo, dryrun bool) (bool, error) {
	changed := false
	opt := install.InstallOption{
		Owner: fi.Owner,
		Group: fi.Group,
		Mode:  &fi.Mode,
	}
	if fi.IsDir {
		differ, err := HasDirDiff(fi.Path, fi.Owner, fi.Group, fi.Mode)
		if err != nil {
			return changed, fmt.Errorf("error at dir diff: %s", err)
		}
		if differ {
			fmt.Println(fi.String())
			changed = true
		}
		if !dryrun && differ {
			if err := install.InstallDir(fi.Path, &opt); err != nil {
				return changed, fmt.Errorf("error at directory installation: %s", err)
			}
		}
	} else {
		differ, err := HasFileDiff(fi.SrcPath, fi.Path)
		if err != nil {
			if !os.IsNotExist(err) {
				return changed, fmt.Errorf("error at file diff: %s", err)
			}
			differ = true
		}
		if differ {
			fmt.Println(fi.String())
			changed = true
		}
		if !dryrun && differ {
			if err := install.InstallFile(fi.SrcPath, fi.Path, &opt); err != nil {
				return changed, fmt.Errorf("error at file installation: %s", err)
			}
		}
	}
	return changed, nil
}