Skip to content

Commit

Permalink
Naming
Browse files Browse the repository at this point in the history
  • Loading branch information
visill committed Aug 3, 2024
1 parent acf5f71 commit cf31169
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func listFunc(con net.Conn, instanceCnf *config.Instance, args []string) error {
r := proc.NewProtoReader(ycl)

done := false
res := make([]*storage.FileInfo, 0)
res := make([]*storage.ObjectInfo, 0)
for {
if done {
break
Expand All @@ -176,7 +176,7 @@ func listFunc(con net.Conn, instanceCnf *config.Instance, args []string) error {

switch tp {
case message.MessageTypeObjectMeta:
meta := message.FilesInfo{}
meta := message.ObjectMetaMessage{}
meta.Decode(body)

res = append(res, meta.Content...)
Expand Down
20 changes: 10 additions & 10 deletions pkg/message/object_meta_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (
"github.com/yezzey-gp/yproxy/pkg/storage"
)

type FilesInfo struct {
Content []*storage.FileInfo
type ObjectMetaMessage struct {
Content []*storage.ObjectInfo
}

var _ ProtoMessage = &FilesInfo{}
var _ ProtoMessage = &ObjectMetaMessage{}

func NewFilesInfo(content []*storage.FileInfo) *FilesInfo {
return &FilesInfo{
func NewObjectMetaMessage(content []*storage.ObjectInfo) *ObjectMetaMessage {
return &ObjectMetaMessage{
Content: content,
}
}

func (c *FilesInfo) Encode() []byte {
func (c *ObjectMetaMessage) Encode() []byte {
bt := []byte{
byte(MessageTypeObjectMeta),
0,
Expand All @@ -42,22 +42,22 @@ func (c *FilesInfo) Encode() []byte {
return append(bs, bt...)
}

func (c *FilesInfo) Decode(body []byte) {
func (c *ObjectMetaMessage) Decode(body []byte) {
body = body[4:]
c.Content = make([]*storage.FileInfo, 0)
c.Content = make([]*storage.ObjectInfo, 0)
for len(body) > 0 {
name, index := c.GetString(body)
size := int64(binary.BigEndian.Uint64(body[index : index+8]))

c.Content = append(c.Content, &storage.FileInfo{
c.Content = append(c.Content, &storage.ObjectInfo{
Path: name,
Size: size,
})
body = body[index+8:]
}
}

func (c *FilesInfo) GetString(b []byte) (string, int) {
func (c *ObjectMetaMessage) GetString(b []byte) (string, int) {
buff := bytes.NewBufferString("")

i := 0
Expand Down
6 changes: 3 additions & 3 deletions pkg/proc/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl
const chunkSize = 1000

for i := 0; i < len(objectMetas); i += chunkSize {
_, err = ycl.GetRW().Write(message.NewFilesInfo(objectMetas[i:min(i+chunkSize, len(objectMetas))]).Encode())
_, err = ycl.GetRW().Write(message.NewObjectMetaMessage(objectMetas[i:min(i+chunkSize, len(objectMetas))]).Encode())
if err != nil {
_ = ycl.ReplyError(err, "failed to upload")

Expand Down Expand Up @@ -221,7 +221,7 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl
return nil
}

var failed []*storage.FileInfo
var failed []*storage.ObjectInfo
retryCount := 0
for len(objectMetas) > 0 && retryCount < 10 {
retryCount++
Expand Down Expand Up @@ -294,7 +294,7 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl client.YproxyCl
}
objectMetas = failed
fmt.Printf("failed files count: %d\n", len(objectMetas))
failed = make([]*storage.FileInfo, 0)
failed = make([]*storage.ObjectInfo, 0)
}

if len(objectMetas) > 0 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/storage/filestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func (s *FileStorageInteractor) CatFileFromStorage(name string, offset int64) (i
_, err = io.CopyN(io.Discard, file, offset)
return file, err
}
func (s *FileStorageInteractor) ListPath(prefix string) ([]*FileInfo, error) {
var data []*FileInfo
func (s *FileStorageInteractor) ListPath(prefix string) ([]*ObjectInfo, error) {
var data []*ObjectInfo
err := filepath.WalkDir(s.cnf.PathToFolder, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
Expand All @@ -36,11 +36,11 @@ func (s *FileStorageInteractor) ListPath(prefix string) ([]*FileInfo, error) {
if err != nil {
return err
}
fileinfo, err := file.Stat()
ObjectInfo, err := file.Stat()
if err != nil {
return err
}
data = append(data, &FileInfo{fileinfo.Name(), fileinfo.Size()})
data = append(data, &ObjectInfo{ObjectInfo.Name(), ObjectInfo.Size()})

Check failure on line 43 in pkg/storage/filestorage.go

View workflow job for this annotation

GitHub Actions / build

ObjectInfo (variable of type fs.FileInfo) is not a type
return nil
})
return data, err
Expand Down
8 changes: 4 additions & 4 deletions pkg/storage/s3storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ func (s *S3StorageInteractor) PatchFile(name string, r io.ReadSeeker, startOffst
return err
}

type FileInfo struct {
type ObjectInfo struct {
Path string
Size int64
}

func (s *S3StorageInteractor) ListPath(prefix string) ([]*FileInfo, error) {
func (s *S3StorageInteractor) ListPath(prefix string) ([]*ObjectInfo, error) {
sess, err := s.pool.GetSession(context.TODO())
if err != nil {
ylogger.Zero.Err(err).Msg("failed to acquire s3 session")
Expand All @@ -107,7 +107,7 @@ func (s *S3StorageInteractor) ListPath(prefix string) ([]*FileInfo, error) {

var continuationToken *string
prefix = path.Join(s.cnf.StoragePrefix, prefix)
metas := make([]*FileInfo, 0)
metas := make([]*ObjectInfo, 0)

for {
input := &s3.ListObjectsV2Input{
Expand All @@ -122,7 +122,7 @@ func (s *S3StorageInteractor) ListPath(prefix string) ([]*FileInfo, error) {
}

for _, obj := range out.Contents {
metas = append(metas, &FileInfo{
metas = append(metas, &ObjectInfo{
Path: *obj.Key,
Size: *obj.Size,
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type StorageWriter interface {
}

type StorageLister interface {
ListPath(prefix string) ([]*FileInfo, error)
ListPath(prefix string) ([]*ObjectInfo, error)
}

type StorageInteractor interface {
Expand Down

0 comments on commit cf31169

Please sign in to comment.