hugofs: Fix golint issues

Fix godoc issues and the following:

hugofs/noop_fs.go:25:2: error var noOpErr should have name of the form errFoo
This commit is contained in:
Cameron Moore 2018-09-06 14:21:18 -05:00 committed by Bjørn Erik Pedersen
parent c8ce65046d
commit 5f2e1cb896
4 changed files with 44 additions and 12 deletions

View file

@ -36,16 +36,20 @@ func (f *realFilenameInfo) RealFilename() string {
return f.realFilename
}
// NewBasePathRealFilenameFs returns a new NewBasePathRealFilenameFs instance
// using base.
func NewBasePathRealFilenameFs(base *afero.BasePathFs) *BasePathRealFilenameFs {
return &BasePathRealFilenameFs{BasePathFs: base}
}
// This is a thin wrapper around afero.BasePathFs that provides the real filename
// in Stat and LstatIfPossible.
// BasePathRealFilenameFs is a thin wrapper around afero.BasePathFs that
// provides the real filename in Stat and LstatIfPossible.
type BasePathRealFilenameFs struct {
*afero.BasePathFs
}
// Stat returns the os.FileInfo structure describing a given file. If there is
// an error, it will be of type *os.PathError.
func (b *BasePathRealFilenameFs) Stat(name string) (os.FileInfo, error) {
fi, err := b.BasePathFs.Stat(name)
if err != nil {
@ -64,6 +68,9 @@ func (b *BasePathRealFilenameFs) Stat(name string) (os.FileInfo, error) {
return &realFilenameInfo{FileInfo: fi, realFilename: filename}, nil
}
// LstatIfPossible returns the os.FileInfo structure describing a given file.
// It attempts to use Lstat if supported or defers to the os. In addition to
// the FileInfo, a boolean is returned telling whether Lstat was called.
func (b *BasePathRealFilenameFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
fi, ok, err := b.BasePathFs.LstatIfPossible(name)

View file

@ -51,6 +51,7 @@ type FilePather interface {
BaseDir() string
}
// LanguageDirsMerger implements the afero.DirsMerger interface.
var LanguageDirsMerger = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error) {
m := make(map[string]*LanguageFileInfo)
@ -84,6 +85,8 @@ var LanguageDirsMerger = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error) {
return merged, nil
}
// LanguageFileInfo is a super-set of os.FileInfo with additional information
// about the file in relation to its Hugo language.
type LanguageFileInfo struct {
os.FileInfo
lang string
@ -99,22 +102,27 @@ type LanguageFileInfo struct {
weight int
}
// Filename returns a file's real filename.
func (fi *LanguageFileInfo) Filename() string {
return fi.realFilename
}
// Path returns a file's relative filename.
func (fi *LanguageFileInfo) Path() string {
return fi.relFilename
}
// RealName returns a file's real name.
func (fi *LanguageFileInfo) RealName() string {
return fi.realName
}
// BaseDir returns a file's base directory.
func (fi *LanguageFileInfo) BaseDir() string {
return fi.baseDir
}
// Lang returns a file's language.
func (fi *LanguageFileInfo) Lang() string {
return fi.lang
}
@ -157,6 +165,7 @@ func (l *languageFile) Readdir(c int) (ofi []os.FileInfo, err error) {
return fis, err
}
// LanguageFs represents a language filesystem.
type LanguageFs struct {
// This Fs is usually created with a BasePathFs
basePath string
@ -166,6 +175,7 @@ type LanguageFs struct {
afero.Fs
}
// NewLanguageFs creates a new LanguageFs.
func NewLanguageFs(lang string, languages map[string]bool, fs afero.Fs) *LanguageFs {
if lang == "" {
panic("no lang set for the language fs")
@ -181,10 +191,12 @@ func NewLanguageFs(lang string, languages map[string]bool, fs afero.Fs) *Languag
return &LanguageFs{lang: lang, languages: languages, basePath: basePath, Fs: fs, nameMarker: marker}
}
// Lang returns a language filesystem's language.
func (fs *LanguageFs) Lang() string {
return fs.lang
}
// Stat returns the os.FileInfo of a given file.
func (fs *LanguageFs) Stat(name string) (os.FileInfo, error) {
name, err := fs.realName(name)
if err != nil {
@ -199,6 +211,7 @@ func (fs *LanguageFs) Stat(name string) (os.FileInfo, error) {
return fs.newLanguageFileInfo(name, fi)
}
// Open opens the named file for reading.
func (fs *LanguageFs) Open(name string) (afero.File, error) {
name, err := fs.realName(name)
if err != nil {
@ -212,6 +225,9 @@ func (fs *LanguageFs) Open(name string) (afero.File, error) {
return &languageFile{File: f, fs: fs}, nil
}
// LstatIfPossible returns the os.FileInfo structure describing a given file.
// It attempts to use Lstat if supported or defers to the os. In addition to
// the FileInfo, a boolean is returned telling whether Lstat was called.
func (fs *LanguageFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
name, err := fs.realName(name)
if err != nil {

View file

@ -22,24 +22,27 @@ import (
)
var (
noOpErr = errors.New("this is a filesystem that does nothing and this operation is not supported")
errNoOp = errors.New("this is a filesystem that does nothing and this operation is not supported")
_ afero.Fs = (*noOpFs)(nil)
NoOpFs = &noOpFs{}
// NoOpFs provides a no-op filesystem that implements the afero.Fs
// interface.
NoOpFs = &noOpFs{}
)
type noOpFs struct {
}
func (fs noOpFs) Create(name string) (afero.File, error) {
return nil, noOpErr
return nil, errNoOp
}
func (fs noOpFs) Mkdir(name string, perm os.FileMode) error {
return noOpErr
return errNoOp
}
func (fs noOpFs) MkdirAll(path string, perm os.FileMode) error {
return noOpErr
return errNoOp
}
func (fs noOpFs) Open(name string) (afero.File, error) {
@ -51,15 +54,15 @@ func (fs noOpFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File,
}
func (fs noOpFs) Remove(name string) error {
return noOpErr
return errNoOp
}
func (fs noOpFs) RemoveAll(path string) error {
return noOpErr
return errNoOp
}
func (fs noOpFs) Rename(oldname string, newname string) error {
return noOpErr
return errNoOp
}
func (fs noOpFs) Stat(name string) (os.FileInfo, error) {
@ -71,9 +74,9 @@ func (fs noOpFs) Name() string {
}
func (fs noOpFs) Chmod(name string, mode os.FileMode) error {
return noOpErr
return errNoOp
}
func (fs noOpFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
return noOpErr
return errNoOp
}

View file

@ -94,6 +94,8 @@ func NewRootMappingFs(fs afero.Fs, fromTo ...string) (*RootMappingFs, error) {
rootMapToReal: rootMapToReal.Commit().Root()}, nil
}
// Stat returns the os.FileInfo structure describing a given file. If there is
// an error, it will be of type *os.PathError.
func (fs *RootMappingFs) Stat(name string) (os.FileInfo, error) {
if fs.isRoot(name) {
return newRootMappingDirFileInfo(name), nil
@ -107,6 +109,7 @@ func (fs *RootMappingFs) isRoot(name string) bool {
}
// Open opens the named file for reading.
func (fs *RootMappingFs) Open(name string) (afero.File, error) {
if fs.isRoot(name) {
return &rootMappingFile{name: name, fs: fs}, nil
@ -119,6 +122,9 @@ func (fs *RootMappingFs) Open(name string) (afero.File, error) {
return &rootMappingFile{File: f, name: name, fs: fs}, nil
}
// LstatIfPossible returns the os.FileInfo structure describing a given file.
// It attempts to use Lstat if supported or defers to the os. In addition to
// the FileInfo, a boolean is returned telling whether Lstat was called.
func (fs *RootMappingFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
if fs.isRoot(name) {
return newRootMappingDirFileInfo(name), false, nil