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