2015-04-05 04:53:41 -04:00
|
|
|
/*
|
|
|
|
* Minimalist Object Storage, (C) 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 donut
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
2015-06-18 19:02:34 -04:00
|
|
|
"path/filepath"
|
2015-06-23 14:44:32 -04:00
|
|
|
|
|
|
|
"github.com/minio/minio/pkg/iodine"
|
2015-04-05 04:53:41 -04:00
|
|
|
)
|
|
|
|
|
2015-04-08 19:28:14 -04:00
|
|
|
// object internal struct
|
2015-04-05 04:53:41 -04:00
|
|
|
type object struct {
|
2015-06-26 05:10:47 -04:00
|
|
|
name string
|
|
|
|
objectPath string
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
|
|
|
|
2015-06-25 00:00:28 -04:00
|
|
|
// newObject - instantiate a new object
|
|
|
|
func newObject(objectName, p string) (object, error) {
|
2015-04-05 04:53:41 -04:00
|
|
|
if objectName == "" {
|
2015-06-24 22:43:38 -04:00
|
|
|
return object{}, iodine.New(InvalidArgument{}, nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
|
|
|
o := object{}
|
|
|
|
o.name = objectName
|
2015-06-18 19:02:34 -04:00
|
|
|
o.objectPath = filepath.Join(p, objectName)
|
2015-04-05 04:53:41 -04:00
|
|
|
return o, nil
|
|
|
|
}
|
|
|
|
|
2015-06-26 05:10:47 -04:00
|
|
|
func (o object) GetObjectMetadata() (*objectMetadata, error) {
|
|
|
|
objectMetadata := new(objectMetadata)
|
2015-06-18 19:02:34 -04:00
|
|
|
objectMetadataBytes, err := ioutil.ReadFile(filepath.Join(o.objectPath, objectMetadataConfig))
|
2015-04-05 04:53:41 -04:00
|
|
|
if err != nil {
|
2015-06-24 23:42:36 -04:00
|
|
|
return nil, iodine.New(ObjectNotFound{Object: o.name}, nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
2015-06-26 05:10:47 -04:00
|
|
|
if err := json.Unmarshal(objectMetadataBytes, objectMetadata); err != nil {
|
2015-06-23 14:44:32 -04:00
|
|
|
return nil, iodine.New(err, nil)
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|
2015-06-26 05:10:47 -04:00
|
|
|
return objectMetadata, nil
|
2015-04-07 18:55:44 -04:00
|
|
|
}
|
|
|
|
|
2015-06-26 05:10:47 -04:00
|
|
|
func (o object) GetDonutObjectMetadata() (*donutObjectMetadata, error) {
|
|
|
|
donutObjectMetadata := new(donutObjectMetadata)
|
2015-06-18 19:02:34 -04:00
|
|
|
donutObjectMetadataBytes, err := ioutil.ReadFile(filepath.Join(o.objectPath, donutObjectMetadataConfig))
|
2015-04-07 18:55:44 -04:00
|
|
|
if err != nil {
|
2015-06-24 23:42:36 -04:00
|
|
|
return nil, iodine.New(ObjectNotFound{Object: o.name}, nil)
|
2015-04-07 18:55:44 -04:00
|
|
|
}
|
2015-06-26 05:10:47 -04:00
|
|
|
if err := json.Unmarshal(donutObjectMetadataBytes, donutObjectMetadata); err != nil {
|
2015-06-23 14:44:32 -04:00
|
|
|
return nil, iodine.New(err, nil)
|
2015-04-07 18:55:44 -04:00
|
|
|
}
|
2015-06-26 05:10:47 -04:00
|
|
|
return donutObjectMetadata, nil
|
2015-04-05 04:53:41 -04:00
|
|
|
}
|