Ejemplo n.º 1
0
Archivo: file.go Proyecto: ycaille/gru
// isDirectoryContentOutdated returns a boolean indicating whether the
// content of the directory managed by the resource is outdated
// compared to the source directory defined by the resource.
// The files identified as being out of date will be appended to the
// list of outdated files for the resource, so they can be further
// processed if needed.
func (f *File) isDirectoryContentOutdated() (bool, error) {
	isOutdated := false
	if f.Source != "" && f.Recursive {
		srcPath := filepath.Join(DefaultConfig.SiteRepo, f.Source)

		// Exclude the ".git" repo directory from the source path,
		// since our source files reside in a git repo
		srcRegistry, err := directoryFileRegistry(srcPath, []string{".git"})
		if err != nil {
			return false, err
		}

		dstRegistry, err := directoryFileRegistry(f.Path, []string{})
		if err != nil {
			return false, err
		}

		// Check source and destination files' content
		for name := range srcRegistry {
			item := &outdatedFile{
				src: srcRegistry[name],
				dst: dstRegistry[name],
			}
			item.flags |= flagOutdatedContent

			// File is missing
			if _, ok := dstRegistry[name]; !ok {
				item.dst = filepath.Join(f.Path, name)
				f.outdated = append(f.outdated, item)
				isOutdated = true
				continue
			}

			// Check if content has changed
			same, err := utils.SameContent(srcRegistry[name], dstRegistry[name])
			if err != nil {
				return false, err
			}

			if !same {
				f.outdated = append(f.outdated, item)
				isOutdated = true
			}
		}

		// Check for extra files in the managed directory
		for name := range dstRegistry {
			if _, ok := srcRegistry[name]; !ok {
				f.extra[dstRegistry[name]] = struct{}{}
			}
		}
	}

	return isOutdated, nil
}
Ejemplo n.º 2
0
Archivo: file.go Proyecto: ycaille/gru
// isRegularFileContentOutdated returns a boolean indicating whether the
// content managed by the resource is outdated compared to the source
// file defined by the resource.
// If the file is identified as being out of date it will be appended to the
// list of outdated files for the resource, so it can be further
// processed if needed.
func (f *File) isRegularFileContentOutdated() (bool, error) {
	if f.Source != "" {
		srcPath := filepath.Join(DefaultConfig.SiteRepo, f.Source)
		same, err := utils.SameContent(srcPath, f.Path)
		if err != nil {
			return false, err
		}

		if !same {
			item := &outdatedFile{
				src: srcPath,
				dst: f.Path,
			}
			item.flags |= flagOutdatedContent
			f.outdated = append(f.outdated, item)
			return true, nil
		}
	}

	return false, nil
}