mirror of
https://github.com/minio/minio.git
synced 2025-01-24 13:13:16 -05:00
Merge pull request #76 from fkautz/pr_out_creating_subdirectories_in_fs_now_works
This commit is contained in:
commit
cbf83f2d38
7
main.go
7
main.go
@ -11,7 +11,8 @@ func parseInput(c *cli.Context) {
|
|||||||
tls := c.Bool("tls")
|
tls := c.Bool("tls")
|
||||||
certFile := c.String("cert")
|
certFile := c.String("cert")
|
||||||
keyFile := c.String("key")
|
keyFile := c.String("key")
|
||||||
server.Start(":8080", tls, certFile, keyFile)
|
inmemory := c.Bool("inmemory")
|
||||||
|
server.Start(":8080", tls, certFile, keyFile, inmemory)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -33,6 +34,10 @@ func main() {
|
|||||||
Value: "",
|
Value: "",
|
||||||
Usage: "key file path",
|
Usage: "key file path",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "inmemory",
|
||||||
|
Usage: "in memory storage",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
app.Flags = flags
|
app.Flags = flags
|
||||||
app.Action = parseInput
|
app.Action = parseInput
|
||||||
|
@ -18,15 +18,19 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/user"
|
||||||
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/minio-io/minio/pkg/httpserver"
|
"github.com/minio-io/minio/pkg/httpserver"
|
||||||
mstorage "github.com/minio-io/minio/pkg/storage"
|
mstorage "github.com/minio-io/minio/pkg/storage"
|
||||||
|
"github.com/minio-io/minio/pkg/storage/fs"
|
||||||
"github.com/minio-io/minio/pkg/storage/inmemory"
|
"github.com/minio-io/minio/pkg/storage/inmemory"
|
||||||
"github.com/minio-io/minio/pkg/webapi/minioapi"
|
"github.com/minio-io/minio/pkg/webapi/minioapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Start(hostname string, tls bool, certFile, keyFile string) {
|
func Start(hostname string, tls bool, certFile, keyFile string, inMemoryStorage bool) {
|
||||||
var ctrlChans []chan<- string
|
var ctrlChans []chan<- string
|
||||||
var statusChans []<-chan error
|
var statusChans []<-chan error
|
||||||
|
|
||||||
@ -44,9 +48,26 @@ func Start(hostname string, tls bool, certFile, keyFile string) {
|
|||||||
srv.KeyFile = keyFile
|
srv.KeyFile = keyFile
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrlChan, statusChan, storage = inmemory.Start()
|
if inMemoryStorage {
|
||||||
ctrlChans = append(ctrlChans, ctrlChan)
|
ctrlChan, statusChan, storage = inmemory.Start()
|
||||||
statusChans = append(statusChans, statusChan)
|
ctrlChans = append(ctrlChans, ctrlChan)
|
||||||
|
statusChans = append(statusChans, statusChan)
|
||||||
|
} else {
|
||||||
|
currentUser, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
rootPath := path.Join(currentUser.HomeDir, "minio-storage")
|
||||||
|
_, err = os.Stat(rootPath)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
err = os.Mkdir(rootPath, 0700)
|
||||||
|
} else if err != nil {
|
||||||
|
log.Fatal("Could not create $HOME/minio-storage", err)
|
||||||
|
}
|
||||||
|
ctrlChan, statusChan, storage = fs.Start(rootPath)
|
||||||
|
ctrlChans = append(ctrlChans, ctrlChan)
|
||||||
|
statusChans = append(statusChans, statusChan)
|
||||||
|
}
|
||||||
|
|
||||||
ctrlChan, statusChan = httpserver.Start(minioapi.HttpHandler(storage), srv)
|
ctrlChan, statusChan = httpserver.Start(minioapi.HttpHandler(storage), srv)
|
||||||
ctrlChans = append(ctrlChans, ctrlChan)
|
ctrlChans = append(ctrlChans, ctrlChan)
|
||||||
|
@ -176,6 +176,13 @@ func (storage *storage) StoreObject(bucket string, key string, data io.Reader) e
|
|||||||
|
|
||||||
// get object path
|
// get object path
|
||||||
objectPath := path.Join(storage.root, bucket, key)
|
objectPath := path.Join(storage.root, bucket, key)
|
||||||
|
objectDir := path.Dir(objectPath)
|
||||||
|
if _, err := os.Stat(objectDir); os.IsNotExist(err) {
|
||||||
|
err = os.MkdirAll(objectDir, 0700)
|
||||||
|
if err != nil {
|
||||||
|
return mstorage.EmbedError(bucket, key, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check if object exists
|
// check if object exists
|
||||||
if _, err := os.Stat(objectPath); !os.IsNotExist(err) {
|
if _, err := os.Stat(objectPath); !os.IsNotExist(err) {
|
||||||
|
@ -15,6 +15,7 @@ func APITestSuite(c *C, create func() Storage) {
|
|||||||
testObjectOverwriteFails(c, create)
|
testObjectOverwriteFails(c, create)
|
||||||
testNonExistantBucketOperations(c, create)
|
testNonExistantBucketOperations(c, create)
|
||||||
testBucketRecreateFails(c, create)
|
testBucketRecreateFails(c, create)
|
||||||
|
testPutObjectInSubdir(c, create)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCreateBucket(c *C, create func() Storage) {
|
func testCreateBucket(c *C, create func() Storage) {
|
||||||
@ -142,3 +143,16 @@ func testBucketRecreateFails(c *C, create func() Storage) {
|
|||||||
err = storage.StoreBucket("string")
|
err = storage.StoreBucket("string")
|
||||||
c.Assert(err, Not(IsNil))
|
c.Assert(err, Not(IsNil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testPutObjectInSubdir(c *C, create func() Storage) {
|
||||||
|
storage := create()
|
||||||
|
err := storage.StoreBucket("bucket")
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
err = storage.StoreObject("bucket", "dir1/dir2/object", bytes.NewBufferString("hello world"))
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
var bytesBuffer bytes.Buffer
|
||||||
|
length, err := storage.CopyObjectToWriter(&bytesBuffer, "bucket", "dir1/dir2/object")
|
||||||
|
c.Assert(len(bytesBuffer.Bytes()), Equals, len("hello world"))
|
||||||
|
c.Assert(int64(len(bytesBuffer.Bytes())), Equals, length)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user