Пример #1
0
func runFileChmod(base_path, path string) bool {
	listener := utils.GetListenerFromDir(base_path)
	rel_path := utils.GetRelativePath(listener, path)
	dbItem, err := datastore.GetOne(base_path, rel_path)
	if err != nil {
		log.Errorf("Error occurred trying to get %s from DB\nError: %s", rel_path, err.Error())
		return false
	}
	fsItem, err := utils.GetFileInfo(path)
	if err != nil {
		log.Errorf("Could not find item on filesystem: %s\nError:%s", path, err.Error())
	}
	if dbItem.Perms != fsItem.Perms {
		iPerm, _ := strconv.Atoi(dbItem.Perms)
		mode := int(iPerm)
		if _, err := os.Stat(path); os.IsNotExist(err) {
			log.Infof("File no longer exists returning")
			return true
		} else {
			err := os.Chmod(path, os.FileMode(mode))
			if err != nil {
				log.Errorf("Error occurred changing file modes: %s", err.Error())
				return false
			}
			return true
		}
	} else {
		log.Info("File modes are correct changing nothing")
		return false
	}
	return true
}
Пример #2
0
func checksumItem(base_path, rel_path, abspath string) bool {
	dbItem, err := datastore.GetOne(base_path, rel_path)
	if err != nil {
		log.Infof("Error occurred getting item from DB: %s", err.Error())
		return false
	} else {
		if dbItem.Checksum != utils.GetMd5Checksum(abspath) {
			log.Infof("%s != DB item checksum", abspath)
			return true
		} else {
			log.Infof("%s === DB item checksum", abspath)
			return false
		}
	}
	return false
}