Skip to content

Commit

Permalink
remove httpFileSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
ungerik committed Aug 28, 2023
1 parent 78a3909 commit 0bdad8b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 101 deletions.
6 changes: 0 additions & 6 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"fmt"
"io"
"io/fs"
"net/http"
"strings"
"time"

Expand Down Expand Up @@ -1204,11 +1203,6 @@ func (file File) GobDecode(gobBytes []byte) error {
return nil
}

// HTTPFileSystem returns a http.FileSystem with the file as root.
func (file File) HTTPFileSystem() http.FileSystem {
return httpFileSystem{root: file}
}

// StdFS wraps the file as a StdFS struct that
// implements the io/fs.FS interface
// of the standard library for a File.
Expand Down
59 changes: 0 additions & 59 deletions httpfilesystem.go

This file was deleted.

129 changes: 93 additions & 36 deletions invalidfilesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,66 @@ import (
"io"
"io/fs"
"net/url"
"os"
"path"
"strings"

"github.com/ungerik/go-fs/fsimpl"
)

// var _ fullyFeaturedFileSystem = InvalidFileSystem{} // TODO implement all FileSystem extensions ?
var _ fullyFeaturedFileSystem = InvalidFileSystem{}

// InvalidFileSystem is a file system where all operations are invalid.
// A File with an empty path defaults to this FS.
type InvalidFileSystem struct{}

func (invalid InvalidFileSystem) IsReadOnly() bool {
func (InvalidFileSystem) IsReadOnly() bool {
return true
}

func (invalid InvalidFileSystem) IsWriteOnly() bool {
func (InvalidFileSystem) IsWriteOnly() bool {
return false
}

func (invalid InvalidFileSystem) RootDir() File {
func (InvalidFileSystem) RootDir() File {
return ""
}

func (invalid InvalidFileSystem) ID() (string, error) {
func (InvalidFileSystem) ID() (string, error) {
return "invalid file system", nil
}

func (invalid InvalidFileSystem) Prefix() string {
func (InvalidFileSystem) Prefix() string {
return "invalid://"
}

func (invalid InvalidFileSystem) Name() string {
func (InvalidFileSystem) Name() string {
return "invalid file system"
}

// String implements the fmt.Stringer interface.
func (invalid InvalidFileSystem) String() string {
func (InvalidFileSystem) String() string {
return "invalid file system"
}

func (invalid InvalidFileSystem) JoinCleanFile(uri ...string) File {
return File(invalid.Prefix() + invalid.JoinCleanPath(uri...))
return File("invalid://" + invalid.JoinCleanPath(uri...))
}

func (invalid InvalidFileSystem) IsAbsPath(filePath string) bool {
func (InvalidFileSystem) IsAbsPath(filePath string) bool {
return path.IsAbs(filePath)
}

func (invalid InvalidFileSystem) AbsPath(filePath string) string {
return invalid.JoinCleanPath(filePath)
}

func (invalid InvalidFileSystem) URL(cleanPath string) string {
return invalid.Prefix() + cleanPath
func (InvalidFileSystem) URL(cleanPath string) string {
return "invalid://" + cleanPath
}

func (invalid InvalidFileSystem) JoinCleanPath(uriParts ...string) string {
func (InvalidFileSystem) JoinCleanPath(uriParts ...string) string {
if len(uriParts) > 0 {
uriParts[0] = strings.TrimPrefix(uriParts[0], invalid.Prefix())
uriParts[0] = strings.TrimPrefix(uriParts[0], "invalid://")
}
cleanPath := path.Join(uriParts...)
unescPath, err := url.PathUnescape(cleanPath)
Expand All @@ -73,77 +75,132 @@ func (invalid InvalidFileSystem) JoinCleanPath(uriParts ...string) string {
return cleanPath
}

func (invalid InvalidFileSystem) SplitPath(filePath string) []string {
filePath = strings.TrimPrefix(filePath, invalid.Prefix())
filePath = strings.TrimPrefix(filePath, "/")
filePath = strings.TrimSuffix(filePath, "/")
func (InvalidFileSystem) SplitPath(filePath string) []string {
filePath = strings.TrimPrefix(filePath, "invalid://")
filePath = strings.Trim(filePath, "/")
return strings.Split(filePath, "/")
}

func (invalid InvalidFileSystem) Separator() string {
func (InvalidFileSystem) Separator() string {
return "/"
}

func (invalid InvalidFileSystem) MatchAnyPattern(name string, patterns []string) (bool, error) {
func (InvalidFileSystem) MatchAnyPattern(name string, patterns []string) (bool, error) {
return false, ErrInvalidFileSystem
}

func (invalid InvalidFileSystem) SplitDirAndName(filePath string) (dir, name string) {
return "", ""
func (InvalidFileSystem) SplitDirAndName(filePath string) (dir, name string) {
return fsimpl.SplitDirAndName(filePath, 0, "/")
}

func (InvalidFileSystem) VolumeName(filePath string) string {
return "invalid:"
}

func (InvalidFileSystem) Stat(filePath string) (fs.FileInfo, error) {
func (InvalidFileSystem) Stat(filePath string) (os.FileInfo, error) {
return nil, ErrInvalidFileSystem
}

func (InvalidFileSystem) Exists(filePath string) bool {
return false
}

func (invalid InvalidFileSystem) IsHidden(filePath string) bool {
func (InvalidFileSystem) IsHidden(filePath string) bool {
return false
}

func (invalid InvalidFileSystem) IsSymbolicLink(filePath string) bool {
func (InvalidFileSystem) IsSymbolicLink(filePath string) bool {
return false
}

func (invalid InvalidFileSystem) ListDirInfo(ctx context.Context, dirPath string, callback func(FileInfo) error, patterns []string) error {
func (InvalidFileSystem) ListDirInfo(ctx context.Context, dirPath string, callback func(FileInfo) error, patterns []string) error {
return ErrInvalidFileSystem
}

func (invalid InvalidFileSystem) ListDirInfoRecursive(ctx context.Context, dirPath string, callback func(FileInfo) error, patterns []string) error {
func (InvalidFileSystem) ListDirInfoRecursive(ctx context.Context, dirPath string, callback func(FileInfo) error, patterns []string) error {
return ErrInvalidFileSystem
}

func (invalid InvalidFileSystem) ListDirMax(ctx context.Context, dirPath string, n int, patterns []string) (files []File, err error) {
func (InvalidFileSystem) ListDirMax(ctx context.Context, dirPath string, n int, patterns []string) (files []File, err error) {
return nil, ErrInvalidFileSystem
}

func (invalid InvalidFileSystem) SetPermissions(filePath string, perm Permissions) error {
func (InvalidFileSystem) SetPermissions(filePath string, perm Permissions) error {
return ErrInvalidFileSystem
}

func (invalid InvalidFileSystem) MakeDir(dirPath string, perm []Permissions) error {
func (InvalidFileSystem) User(filePath string) string {
return ""
}

func (InvalidFileSystem) SetUser(filePath string, user string) error {
return ErrInvalidFileSystem
}

func (invalid InvalidFileSystem) OpenReader(filePath string) (fs.File, error) {
func (InvalidFileSystem) Group(filePath string) string {
return ""
}

func (InvalidFileSystem) SetGroup(filePath string, group string) error {
return ErrInvalidFileSystem
}

func (InvalidFileSystem) Touch(filePath string, perm []Permissions) error {
return ErrInvalidFileSystem
}

func (InvalidFileSystem) MakeDir(dirPath string, perm []Permissions) error {
return ErrInvalidFileSystem
}

func (InvalidFileSystem) ReadAll(ctx context.Context, filePath string) ([]byte, error) {
return nil, ErrInvalidFileSystem
}

func (invalid InvalidFileSystem) OpenWriter(filePath string, perm []Permissions) (io.WriteCloser, error) {
func (InvalidFileSystem) WriteAll(ctx context.Context, filePath string, data []byte, perm []Permissions) error {
return ErrInvalidFileSystem
}

func (InvalidFileSystem) Append(ctx context.Context, filePath string, data []byte, perm []Permissions) error {
return ErrInvalidFileSystem
}

func (InvalidFileSystem) OpenReader(filePath string) (fs.File, error) {
return nil, ErrInvalidFileSystem
}

func (InvalidFileSystem) OpenWriter(filePath string, perm []Permissions) (io.WriteCloser, error) {
return nil, ErrInvalidFileSystem
}

func (InvalidFileSystem) OpenAppendWriter(filePath string, perm []Permissions) (io.WriteCloser, error) {
return nil, ErrInvalidFileSystem
}

func (InvalidFileSystem) OpenReadWriter(filePath string, perm []Permissions) (ReadWriteSeekCloser, error) {
return nil, ErrInvalidFileSystem
}

func (invalid InvalidFileSystem) OpenReadWriter(filePath string, perm []Permissions) (ReadWriteSeekCloser, error) {
func (InvalidFileSystem) Watch(filePath string, onEvent func(File, Event)) (cancel func() error, err error) {
return nil, ErrInvalidFileSystem
}

func (invalid InvalidFileSystem) Truncate(filePath string, size int64) error {
func (InvalidFileSystem) Truncate(filePath string, size int64) error {
return ErrInvalidFileSystem
}

func (InvalidFileSystem) CopyFile(ctx context.Context, srcFile string, destFile string, buf *[]byte) error {
return ErrInvalidFileSystem
}

func (InvalidFileSystem) Rename(filePath string, newName string) (string, error) {
return "", ErrInvalidFileSystem
}

func (InvalidFileSystem) Move(filePath string, destPath string) error {
return ErrInvalidFileSystem
}

func (invalid InvalidFileSystem) Remove(filePath string) error {
func (InvalidFileSystem) Remove(filePath string) error {
return ErrInvalidFileSystem
}

0 comments on commit 0bdad8b

Please sign in to comment.