From 5bdd16a4965d0caf5c3bb7ce4ef97304d298a3c2 Mon Sep 17 00:00:00 2001 From: Starnop Date: Thu, 25 Apr 2019 11:25:04 +0800 Subject: [PATCH] bugfix: update the fileds of store.Raw to uppercase Signed-off-by: Starnop --- supernode/store/local_storage.go | 48 +++++++++++++-------------- supernode/store/local_storage_test.go | 30 ++++++++--------- supernode/store/storage_driver.go | 8 ++--- supernode/store/store.go | 12 +++---- 4 files changed, 49 insertions(+), 49 deletions(-) diff --git a/supernode/store/local_storage.go b/supernode/store/local_storage.go index c5515b87c..2c28da75d 100644 --- a/supernode/store/local_storage.go +++ b/supernode/store/local_storage.go @@ -107,13 +107,13 @@ func NewLocalStorage(conf string) (StorageDriver, error) { // Get the content of key from storage and return in io stream. func (ls *localStorage) Get(ctx context.Context, raw *Raw, writer io.Writer) error { - path, _, err := ls.statPath(raw.key) + path, _, err := ls.statPath(raw.Key) if err != nil { return err } - lock(getLockKey(path, raw.offset), true) - defer releaseLock(getLockKey(path, raw.offset), true) + lock(getLockKey(path, raw.Offset), true) + defer releaseLock(getLockKey(path, raw.Offset), true) f, err := os.Open(path) if err != nil { @@ -121,11 +121,11 @@ func (ls *localStorage) Get(ctx context.Context, raw *Raw, writer io.Writer) err } defer f.Close() - f.Seek(raw.offset, 0) - if raw.length <= 0 { + f.Seek(raw.Offset, 0) + if raw.Length <= 0 { _, err = io.Copy(writer, f) } else { - _, err = io.CopyN(writer, f, raw.length) + _, err = io.CopyN(writer, f, raw.Length) } if err != nil { @@ -136,13 +136,13 @@ func (ls *localStorage) Get(ctx context.Context, raw *Raw, writer io.Writer) err // GetBytes gets the content of key from storage and return in bytes. func (ls *localStorage) GetBytes(ctx context.Context, raw *Raw) (data []byte, err error) { - path, _, err := ls.statPath(raw.key) + path, _, err := ls.statPath(raw.Key) if err != nil { return nil, err } - lock(getLockKey(path, raw.offset), true) - defer releaseLock(getLockKey(path, raw.offset), true) + lock(getLockKey(path, raw.Offset), true) + defer releaseLock(getLockKey(path, raw.Offset), true) f, err := os.Open(path) if err != nil { @@ -150,11 +150,11 @@ func (ls *localStorage) GetBytes(ctx context.Context, raw *Raw) (data []byte, er } defer f.Close() - f.Seek(raw.offset, 0) - if raw.length <= 0 { + f.Seek(raw.Offset, 0) + if raw.Length <= 0 { data, err = ioutil.ReadAll(f) } else { - data = make([]byte, raw.length) + data = make([]byte, raw.Length) _, err = f.Read(data) } @@ -166,13 +166,13 @@ func (ls *localStorage) GetBytes(ctx context.Context, raw *Raw) (data []byte, er // Put reads the content from reader and put it into storage. func (ls *localStorage) Put(ctx context.Context, raw *Raw, data io.Reader) error { - path, err := ls.preparePath(raw.key) + path, err := ls.preparePath(raw.Key) if err != nil { return err } - lock(getLockKey(path, raw.offset), false) - defer releaseLock(getLockKey(path, raw.offset), false) + lock(getLockKey(path, raw.Offset), false) + defer releaseLock(getLockKey(path, raw.Offset), false) f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC|os.O_SYNC, 0644) if err != nil { @@ -180,7 +180,7 @@ func (ls *localStorage) Put(ctx context.Context, raw *Raw, data io.Reader) error } defer f.Close() - f.Seek(raw.offset, 0) + f.Seek(raw.Offset, 0) if _, err = io.Copy(f, data); err != nil { return err } @@ -190,13 +190,13 @@ func (ls *localStorage) Put(ctx context.Context, raw *Raw, data io.Reader) error // PutBytes puts the content of key from storage with bytes. func (ls *localStorage) PutBytes(ctx context.Context, raw *Raw, data []byte) error { - path, err := ls.preparePath(raw.key) + path, err := ls.preparePath(raw.Key) if err != nil { return err } - lock(getLockKey(path, raw.offset), false) - defer releaseLock(getLockKey(path, raw.offset), false) + lock(getLockKey(path, raw.Offset), false) + defer releaseLock(getLockKey(path, raw.Offset), false) f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC|os.O_SYNC, 0644) if err != nil { @@ -204,7 +204,7 @@ func (ls *localStorage) PutBytes(ctx context.Context, raw *Raw, data []byte) err } defer f.Close() - f.Seek(raw.offset, 0) + f.Seek(raw.Offset, 0) if _, err := f.Write(data); err != nil { return err } @@ -214,7 +214,7 @@ func (ls *localStorage) PutBytes(ctx context.Context, raw *Raw, data []byte) err // Stat determine whether the file exists. func (ls *localStorage) Stat(ctx context.Context, raw *Raw) (*StorageInfo, error) { - path, fileInfo, err := ls.statPath(raw.key) + path, fileInfo, err := ls.statPath(raw.Key) if err != nil { return nil, err } @@ -233,13 +233,13 @@ func (ls *localStorage) Stat(ctx context.Context, raw *Raw) (*StorageInfo, error // Remove deletes a file or dir. func (ls *localStorage) Remove(ctx context.Context, raw *Raw) error { - path, _, err := ls.statPath(raw.key) + path, _, err := ls.statPath(raw.Key) if err != nil { return err } - lock(getLockKey(path, raw.offset), false) - defer releaseLock(getLockKey(path, raw.offset), false) + lock(getLockKey(path, raw.Offset), false) + defer releaseLock(getLockKey(path, raw.Offset), false) if err := os.RemoveAll(path); err != nil { return err diff --git a/supernode/store/local_storage_test.go b/supernode/store/local_storage_test.go index dc09452f3..48a0f848f 100644 --- a/supernode/store/local_storage_test.go +++ b/supernode/store/local_storage_test.go @@ -88,25 +88,25 @@ func (s *LocalStorageSuite) TestGetPutBytes(c *check.C) { }{ { raw: &Raw{ - key: "foo1", + Key: "foo1", }, data: []byte("hello foo"), expected: "hello foo", }, { raw: &Raw{ - key: "foo2", - offset: 0, - length: 5, + Key: "foo2", + Offset: 0, + Length: 5, }, data: []byte("hello foo"), expected: "hello", }, { raw: &Raw{ - key: "foo3", - offset: 2, - length: -1, + Key: "foo3", + Offset: 2, + Length: -1, }, data: []byte("hello foo"), expected: "hello foo", @@ -139,25 +139,25 @@ func (s *LocalStorageSuite) TestGetPut(c *check.C) { }{ { raw: &Raw{ - key: "foo1.meta", + Key: "foo1.meta", }, data: strings.NewReader("hello meta file"), expected: "hello meta file", }, { raw: &Raw{ - key: "foo2.meta", - offset: 2, - length: 5, + Key: "foo2.meta", + Offset: 2, + Length: 5, }, data: strings.NewReader("hello meta file"), expected: "hello", }, { raw: &Raw{ - key: "foo3.meta", - offset: 2, - length: -1, + Key: "foo3.meta", + Offset: 2, + Length: -1, }, data: strings.NewReader("hello meta file"), expected: "hello meta file", @@ -206,7 +206,7 @@ func (s *LocalStorageSuite) checkStat(raw *Raw, c *check.C) { c.Assert(err, check.IsNil) driver := s.storeLocal.driver.(*localStorage) - pathTemp := path.Join(driver.BaseDir, getPrefix(raw.key), raw.key) + pathTemp := path.Join(driver.BaseDir, getPrefix(raw.Key), raw.Key) f, _ := os.Stat(pathTemp) sys, _ := util.GetSys(f) diff --git a/supernode/store/storage_driver.go b/supernode/store/storage_driver.go index 97eeaecc8..253c39363 100644 --- a/supernode/store/storage_driver.go +++ b/supernode/store/storage_driver.go @@ -73,10 +73,10 @@ type StorageDriver interface { // Raw identifies a piece of data uniquely. // If the length<=0, it represents all data. type Raw struct { - bucket string - key string - offset int64 - length int64 + Bucket string + Key string + Offset int64 + Length int64 } // StorageInfo includes partial meta information of the data. diff --git a/supernode/store/store.go b/supernode/store/store.go index 4a4d01970..199f4abb1 100644 --- a/supernode/store/store.go +++ b/supernode/store/store.go @@ -66,7 +66,7 @@ func (s *Store) Name() string { // Get the data from the storage driver in io stream. func (s *Store) Get(ctx context.Context, raw *Raw, writer io.Writer) error { - if err := isEmptyKey(raw.key); err != nil { + if err := isEmptyKey(raw.Key); err != nil { return err } return s.driver.Get(ctx, raw, writer) @@ -74,7 +74,7 @@ func (s *Store) Get(ctx context.Context, raw *Raw, writer io.Writer) error { // GetBytes gets the data from the storage driver in bytes. func (s *Store) GetBytes(ctx context.Context, raw *Raw) ([]byte, error) { - if err := isEmptyKey(raw.key); err != nil { + if err := isEmptyKey(raw.Key); err != nil { return nil, err } return s.driver.GetBytes(ctx, raw) @@ -82,7 +82,7 @@ func (s *Store) GetBytes(ctx context.Context, raw *Raw) ([]byte, error) { // Put puts data into the storage in io stream. func (s *Store) Put(ctx context.Context, raw *Raw, data io.Reader) error { - if err := isEmptyKey(raw.key); err != nil { + if err := isEmptyKey(raw.Key); err != nil { return err } return s.driver.Put(ctx, raw, data) @@ -90,7 +90,7 @@ func (s *Store) Put(ctx context.Context, raw *Raw, data io.Reader) error { // PutBytes puts data into the storage in bytes. func (s *Store) PutBytes(ctx context.Context, raw *Raw, data []byte) error { - if err := isEmptyKey(raw.key); err != nil { + if err := isEmptyKey(raw.Key); err != nil { return err } return s.driver.PutBytes(ctx, raw, data) @@ -98,7 +98,7 @@ func (s *Store) PutBytes(ctx context.Context, raw *Raw, data []byte) error { // Remove the data from the storage based on raw information. func (s *Store) Remove(ctx context.Context, raw *Raw) error { - if err := isEmptyKey(raw.key); err != nil { + if err := isEmptyKey(raw.Key); err != nil { return err } return s.driver.Remove(ctx, raw) @@ -108,7 +108,7 @@ func (s *Store) Remove(ctx context.Context, raw *Raw) error { // If that, and return some info that in the form of struct StorageInfo. // If not, return the ErrNotFound. func (s *Store) Stat(ctx context.Context, raw *Raw) (*StorageInfo, error) { - if err := isEmptyKey(raw.key); err != nil { + if err := isEmptyKey(raw.Key); err != nil { return nil, err } return s.driver.Stat(ctx, raw)