Esempio n. 1
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
}
Esempio n. 2
0
func main() {
	kingpin.Parse()

	opt := &install.InstallOption{}
	if *owner != "" {
		opt.Owner = *owner
	}
	if *group != "" {
		opt.Group = *group
	}
	if *mode != "" {
		m, err := strconv.ParseInt(*mode, 8, 32)
		if err != nil {
			fmt.Printf("invalid mode: %s", err)
			os.Exit(-1)
		}
		mode := os.FileMode(m)
		opt.Mode = &mode
	}

	args := *_args
	if *dir {
		for _, name := range args {
			install.InstallDir(name, opt)
		}
		return
	}

	sources := args[:len(args)-1]
	dst := args[len(args)-1]
	if len(sources) > 1 {
		if err := checkDst(dst); err != nil {
			fmt.Println(err.Error())
			os.Exit(-1)
		}
	}
	installFile(sources, dst, opt)
}