fs

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGetFileStats is returned when it fails to get file stat.
	ErrGetFileStats = errors.New("can't get stat for file")
	// ErrNotYAMLFile is returned in case the path doesn't have a valid yaml extension.
	ErrNotYAMLFile = errors.New("file is a directory or is not an accepted YAML extension")
)
View Source
var (
	ErrFolderNotFound = errors.New("folder not found")
	ErrFilesNotFound  = errors.New("files not found")
)

Errors

View Source
var (
	// OSFilesInFolderFn returns the list of hopefully readable files for a folder.
	// This is a best effort guessing readability as official Go authors say:
	// > only reliable strategy is to just try to open it for read and see if it fails
	// https://golang-dev.narkive.com/FJOvNshy/isreadable-iswriteable-isfile-touch
	OSFilesInFolderFn = func(folderPath string) (filePaths []string, err error) {
		files, err := ioutil.ReadDir(folderPath)
		if err != nil {
			if _, ok := err.(*os.PathError); ok {
				err = ErrFolderNotFound
			}
			return
		}

		for _, file := range files {
			if !file.IsDir() {
				perm := file.Mode().Perm()
				if perm&readableMask == 0 {
					continue
				}
				filePaths = append(filePaths, filepath.Join(folderPath, file.Name()))
			}
		}

		if len(filePaths) == 0 {
			err = ErrFilesNotFound
		}

		return
	}
)

Functions

func ValidateYAMLFile

func ValidateYAMLFile(filename string, beingDeleted bool) error

ValidateYAMLFile checks if the file exists(excepting if it has been marked for deletion) and if its it has a YAML extension.

Types

type FilesInFolderFn

type FilesInFolderFn func(folderPath string) (filePaths []string, err error)

FilesInFolderFn returns the files (paths) within a folder (path).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL