Beispiel #1
0
// ModTimeAfter checks if the provided file modification time is older than the one passed in as paramter
// It returns error if os.Stat returns error
func ModTimeAfter(f resource.Filer, mtime time.Time) error {
	fi, err := f.Info()
	if err != nil {
		return err
	}
	if fi.ModTime().After(mtime) {
		return nil
	}
	return fmt.Errorf("%s modification time is bigger than %s", f, mtime)
}
Beispiel #2
0
// Size checks if the provided file byte size is the same as the one passed in as paramter
// It returns error if os.Stat returns error
func Size(f resource.Filer, size int64) error {
	fi, err := f.Info()
	if err != nil {
		return err
	}
	if fi.Size() == size {
		return nil
	}
	return fmt.Errorf("%s size is different from %d", f, size)
}
Beispiel #3
0
// IsGrupedInto checks if the provided file is owned by groupname group
// It returns an error if os.Stat returns error
func IsGrupedInto(f resource.Filer, groupname string) error {
	fi, err := f.Info()
	if err != nil {
		return err
	}
	gid, err := utils.RoleToID("group", groupname)
	if err != nil {
		return err
	}
	return isTrueOrError(fi.Sys().(*syscall.Stat_t).Gid == uint32(gid), fmt.Errorf("%s file is not grouped to %s", f, groupname))
}
Beispiel #4
0
// IsOwnedBy checks if the provided file is owned by username user
// It returns an error if os.Stat returns error
func IsOwnedBy(f resource.Filer, username string) error {
	fi, err := f.Info()
	if err != nil {
		return nil
	}
	uid, err := utils.RoleToID("user", username)
	if err != nil {
		return err
	}
	return isTrueOrError(fi.Sys().(*syscall.Stat_t).Uid == uint32(uid), fmt.Errorf("%s file is not owned by %s", f, username))
}
Beispiel #5
0
// IsMode checks if the provided file has the same mode as the one passed in via paramter
// It returns error if os.Stat returns error
func IsMode(f resource.Filer, mode os.FileMode) error {
	fi, err := f.Info()
	if err != nil {
		return err
	}

	if verboseMode, ok := verboseNames[mode]; ok {
		err = fmt.Errorf("%s file is not a %s", f, verboseMode)
	} else {
		err = fmt.Errorf("%s file is not mode %v", f, mode)
	}
	return isTrueOrError(fi.Mode()&mode != 0, err)
}