Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
bugfix: update the fileds of store.Raw to uppercase
Browse files Browse the repository at this point in the history
Signed-off-by: Starnop <[email protected]>
  • Loading branch information
starnop committed Apr 25, 2019
1 parent a5d510a commit 5bdd16a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 49 deletions.
48 changes: 24 additions & 24 deletions supernode/store/local_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,25 @@ 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 {
return 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 {
Expand All @@ -136,25 +136,25 @@ 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 {
return nil, err
}
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)
}

Expand All @@ -166,21 +166,21 @@ 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 {
return err
}
defer f.Close()

f.Seek(raw.offset, 0)
f.Seek(raw.Offset, 0)
if _, err = io.Copy(f, data); err != nil {
return err
}
Expand All @@ -190,21 +190,21 @@ 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 {
return err
}
defer f.Close()

f.Seek(raw.offset, 0)
f.Seek(raw.Offset, 0)
if _, err := f.Write(data); err != nil {
return err
}
Expand All @@ -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
}
Expand All @@ -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
Expand Down
30 changes: 15 additions & 15 deletions supernode/store/local_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions supernode/store/storage_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions supernode/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,39 +66,39 @@ 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)
}

// 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)
}

// 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)
}

// 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)
}

// 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)
Expand All @@ -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)
Expand Down

0 comments on commit 5bdd16a

Please sign in to comment.