mirror of
https://github.com/minio/mc.git
synced 2025-11-13 12:22:45 +03:00
Implement 'mkdir'
This commit is contained in:
@@ -19,3 +19,4 @@ var configSecretErr = errors.New("secretkey is mandatory")
|
||||
var missingAccessSecretErr = errors.New("You can configure your credentials by running `mc configure`")
|
||||
var missingAccessErr = errors.New("Partial credentials found in the env, missing : AWS_ACCESS_KEY_ID")
|
||||
var missingSecretErr = errors.New("Partial credentials found in the env, missing : AWS_SECRET_ACCESS_KEY")
|
||||
var invalidBucketErr = errors.New("Invalid bucket name")
|
||||
|
||||
47
fs-mkdir.go
Normal file
47
fs-mkdir.go
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/mc/pkg/s3"
|
||||
)
|
||||
|
||||
func doFsMkdir(c *cli.Context) {
|
||||
switch len(c.Args()) {
|
||||
case 1:
|
||||
if !s3.IsValidBucket(c.Args().Get(0)) {
|
||||
log.Fatal(invalidBucketErr)
|
||||
}
|
||||
default:
|
||||
log.Fatal()
|
||||
}
|
||||
bucketName := c.Args().Get(0)
|
||||
var err error
|
||||
var auth *s3.Auth
|
||||
auth, err = getAWSEnvironment()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
s3c := s3.NewS3Client(auth)
|
||||
err = s3c.PutBucket(bucketName)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -56,8 +56,5 @@ type fsOptions struct {
|
||||
isput bool
|
||||
}
|
||||
|
||||
func doFsMkdir(c *cli.Context) {
|
||||
}
|
||||
|
||||
func doFsSync(c *cli.Context) {
|
||||
}
|
||||
|
||||
@@ -127,6 +127,26 @@ func (c *Client) Stat(key, bucket string) (size int64, reterr error) {
|
||||
return 0, fmt.Errorf("s3: Unexpected status code %d statting object %v", res.StatusCode, key)
|
||||
}
|
||||
|
||||
func (c *Client) PutBucket(bucket string) error {
|
||||
req := newReq(c.bucketURL(bucket))
|
||||
req.Method = "PUT"
|
||||
c.Auth.SignRequest(req)
|
||||
res, err := c.transport().RoundTrip(req)
|
||||
if res != nil && res.Body != nil {
|
||||
defer res.Body.Close()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if res.StatusCode != http.StatusOK {
|
||||
// res.Write(os.Stderr)
|
||||
return fmt.Errorf("Got response code %d from s3", res.StatusCode)
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (c *Client) Put(bucket, key string, md5 hash.Hash, size int64, body io.Reader) error {
|
||||
req := newReq(c.keyURL(bucket, key))
|
||||
req.Method = "PUT"
|
||||
|
||||
Reference in New Issue
Block a user