all: Remove unused code

Using x/tools/cmd/deadcode
This commit is contained in:
Bjørn Erik Pedersen
2023-12-18 17:41:15 +01:00
parent 6f13430d4a
commit 8adba648cc
30 changed files with 32 additions and 405 deletions

View File

@@ -15,6 +15,7 @@
package hugofs
import (
"errors"
"os"
"path/filepath"
"reflect"
@@ -28,8 +29,6 @@ import (
"github.com/gohugoio/hugo/hugofs/files"
"golang.org/x/text/unicode/norm"
"errors"
"github.com/gohugoio/hugo/common/hreflect"
"github.com/gohugoio/hugo/common/htime"
@@ -224,7 +223,8 @@ func newDirNameOnlyFileInfo(name string, meta *FileMeta, fileOpener func() (afer
func decorateFileInfo(
fi os.FileInfo,
fs afero.Fs, opener func() (afero.File, error),
filename, filepath string, inMeta *FileMeta) FileMetaInfo {
filename, filepath string, inMeta *FileMeta,
) FileMetaInfo {
var meta *FileMeta
var fim FileMetaInfo
@@ -289,13 +289,6 @@ func fileInfosToNames(fis []os.FileInfo) []string {
return names
}
func fromSlash(filenames []string) []string {
for i, name := range filenames {
filenames[i] = filepath.FromSlash(name)
}
return filenames
}
func sortFileInfos(fis []os.FileInfo) {
sort.Slice(fis, func(i, j int) bool {
fimi, fimj := fis[i].(FileMetaInfo), fis[j].(FileMetaInfo)

View File

@@ -23,9 +23,7 @@ import (
"github.com/spf13/afero"
)
var (
_ FilesystemUnwrapper = (*filenameFilterFs)(nil)
)
var _ FilesystemUnwrapper = (*filenameFilterFs)(nil)
func newFilenameFilterFs(fs afero.Fs, base string, filter *glob.FilenameFilter) afero.Fs {
return &filenameFilterFs{
@@ -93,12 +91,6 @@ func (fs *filenameFilterFs) Stat(name string) (os.FileInfo, error) {
return fi, err
}
func (fs *filenameFilterFs) getOpener(name string) func() (afero.File, error) {
return func() (afero.File, error) {
return fs.Open(name)
}
}
type filenameFilterDir struct {
afero.File
base string
@@ -162,9 +154,11 @@ func (fs *filenameFilterFs) RemoveAll(p string) error {
func (fs *filenameFilterFs) Rename(o, n string) error {
return syscall.EPERM
}
func (fs *filenameFilterFs) Create(n string) (afero.File, error) {
return nil, syscall.EPERM
}
func (fs *filenameFilterFs) Name() string {
return "FinameFilterFS"
}

View File

@@ -60,14 +60,7 @@ type Fs struct {
WorkingDirWritable afero.Fs
}
// NewDefault creates a new Fs with the OS file system
// as source and destination file systems.
func NewDefault(conf config.BaseConfig) *Fs {
fs := Os
return NewFrom(fs, conf)
}
func NewDefaultOld(cfg config.Provider) *Fs {
func NewDefault(cfg config.Provider) *Fs {
workingDir, publishDir := getWorkingPublishDir(cfg)
fs := Os
return newFs(fs, fs, workingDir, publishDir)
@@ -99,7 +92,6 @@ func getWorkingPublishDir(cfg config.Provider) (string, string) {
publishDir = cfg.GetString("publishDir")
}
return workingDir, publishDir
}
func newFs(source, destination afero.Fs, workingDir, publishDir string) *Fs {
@@ -166,7 +158,7 @@ func MakeReadableAndRemoveAllModulePkgDir(fs afero.Fs, dir string) (int, error)
}
if info.IsDir() {
counter++
fs.Chmod(path, 0777)
fs.Chmod(path, 0o777)
}
return nil
})
@@ -217,7 +209,6 @@ func WalkFilesystems(fs afero.Fs, fn WalkFn) bool {
if WalkFilesystems(afs.UnwrapFilesystem(), fn) {
return true
}
} else if bfs, ok := fs.(FilesystemsUnwrapper); ok {
for _, sf := range bfs.UnwrapFilesystems() {
if WalkFilesystems(sf, fn) {

View File

@@ -30,7 +30,6 @@ func TestIsOsFs(t *testing.T) {
c.Assert(IsOsFs(&afero.MemMapFs{}), qt.Equals, false)
c.Assert(IsOsFs(afero.NewBasePathFs(&afero.MemMapFs{}, "/public")), qt.Equals, false)
c.Assert(IsOsFs(afero.NewBasePathFs(Os, t.TempDir())), qt.Equals, true)
}
func TestNewDefault(t *testing.T) {
@@ -38,7 +37,7 @@ func TestNewDefault(t *testing.T) {
v := config.New()
v.Set("workingDir", t.TempDir())
v.Set("publishDir", "public")
f := NewDefaultOld(v)
f := NewDefault(v)
c.Assert(f.Source, qt.IsNotNil)
c.Assert(f.Source, hqt.IsSameType, new(afero.OsFs))