Merge remote-tracking branch 'upstream/main'
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/tenrok/filestore/remote"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -20,7 +21,7 @@ var (
|
||||
ErrNotSupported = errors.New("doesn't support this operation")
|
||||
)
|
||||
|
||||
var _ http.File = (*MinioFile)(nil)
|
||||
var _ remote.File = (*MinioFile)(nil)
|
||||
|
||||
type MinioFile struct {
|
||||
openFlags int
|
||||
|
||||
@@ -3,7 +3,6 @@ package miniostorage
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -70,17 +69,17 @@ func (s *MinioStorage) normSeparators(str string) string {
|
||||
}
|
||||
|
||||
// Create
|
||||
func (s *MinioStorage) Create(name string) (http.File, error) {
|
||||
func (s *MinioStorage) Create(name string) (remote.File, error) {
|
||||
return s.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0)
|
||||
}
|
||||
|
||||
// Open
|
||||
func (s *MinioStorage) Open(name string) (http.File, error) {
|
||||
func (s *MinioStorage) Open(name string) (remote.File, error) {
|
||||
return s.OpenFile(name, os.O_RDONLY, 0)
|
||||
}
|
||||
|
||||
// OpenFile
|
||||
func (s *MinioStorage) OpenFile(name string, flag int, fileMode os.FileMode) (http.File, error) {
|
||||
func (s *MinioStorage) OpenFile(name string, flag int, fileMode os.FileMode) (remote.File, error) {
|
||||
if flag&os.O_APPEND != 0 {
|
||||
return nil, errors.New("appending files will lead to trouble")
|
||||
}
|
||||
|
||||
+14
-4
@@ -3,7 +3,8 @@ package remote
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
@@ -13,11 +14,20 @@ var (
|
||||
storages = make(map[string]Storage)
|
||||
)
|
||||
|
||||
type File interface {
|
||||
io.Closer
|
||||
io.Reader
|
||||
io.Seeker
|
||||
io.Writer
|
||||
Readdir(count int) ([]fs.FileInfo, error)
|
||||
Stat() (fs.FileInfo, error)
|
||||
}
|
||||
|
||||
type Storage interface {
|
||||
NewStorage(ctx context.Context, connString string) (Storage, error)
|
||||
Create(name string) (http.File, error)
|
||||
Open(name string) (http.File, error)
|
||||
OpenFile(name string, flag int, fileMode os.FileMode) (http.File, error)
|
||||
Create(name string) (File, error)
|
||||
Open(name string) (File, error)
|
||||
OpenFile(name string, flag int, fileMode os.FileMode) (File, error)
|
||||
Remove(name string) error
|
||||
RemoveAll(path string) error
|
||||
Rename(oldName, newName string) error
|
||||
|
||||
Reference in New Issue
Block a user