Skip to content

Commit

Permalink
refactor names
Browse files Browse the repository at this point in the history
  • Loading branch information
debebantur committed May 26, 2024
1 parent 846bb35 commit 23ac931
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ var copyCmd = &cobra.Command{
ylogger.Zero.Debug().Bytes("msg", msg).Msg("constructed copy msg")

client := client.NewYClient(con)
pr := proc.NewProtoReader(client)
protoReader := proc.NewProtoReader(client)

ansType, body, err := pr.ReadPacket()
ansType, body, err := protoReader.ReadPacket()
if err != nil {
ylogger.Zero.Debug().Err(err).Msg("error while ans")
return err
Expand Down
24 changes: 12 additions & 12 deletions pkg/proc/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl *client.YClient
path := strings.TrimPrefix(objectMetas[i].Path, instanceCnf.StorageCnf.StoragePrefix)

//get reader
yr := NewYRetryReader(NewRestartReader(oldStorage, path))
readerFromOldBucket := NewYRetryReader(NewRestartReader(oldStorage, path))
var fromReader io.Reader
fromReader = yr
defer yr.Close()
fromReader = readerFromOldBucket
defer readerFromOldBucket.Close()

if msg.Decrypt {
fromReader, err = cr.Decrypt(yr)
fromReader, err = cr.Decrypt(readerFromOldBucket)
if err != nil {
ylogger.Zero.Error().Err(err).Msg("failed to decrypt object")
failed = append(failed, objectMetas[i])
Expand All @@ -216,42 +216,42 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl *client.YClient
}

//reencrypt
r, w := io.Pipe()
readerEncrypt, writerEncrypt := io.Pipe()

go func() {
defer func() {
if err := w.Close(); err != nil {
if err := writerEncrypt.Close(); err != nil {
ylogger.Zero.Warn().Err(err).Msg("failed to close writer")
}
}()

var ww io.WriteCloser = w
var writerToNewBucket io.WriteCloser = writerEncrypt

if msg.Encrypt {
var err error
ww, err = cr.Encrypt(w)
writerToNewBucket, err = cr.Encrypt(writerEncrypt)
if err != nil {
ylogger.Zero.Error().Err(err).Msg("failed to encrypt object")
failed = append(failed, objectMetas[i])
return
}
}

if _, err := io.Copy(ww, fromReader); err != nil {
if _, err := io.Copy(writerToNewBucket, fromReader); err != nil {
ylogger.Zero.Error().Err(err).Msg("failed to copy data")
failed = append(failed, objectMetas[i])
return
}

if err := ww.Close(); err != nil {
if err := writerToNewBucket.Close(); err != nil {
ylogger.Zero.Error().Err(err).Msg("failed to close writer")
failed = append(failed, objectMetas[i])
return
}
}()

//write file
err = s.PutFileToDest(path, r)
err = s.PutFileToDest(path, readerEncrypt)
if err != nil {
ylogger.Zero.Error().Err(err).Msg("failed to upload file")
failed = append(failed, objectMetas[i])
Expand Down Expand Up @@ -281,7 +281,7 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl *client.YClient
ylogger.Zero.Info().Msg("Copy finished successfully")

default:
ylogger.Zero.Error().Any("type", tp).Msg("what tip is it")
ylogger.Zero.Error().Any("type", tp).Msg("what type is it")
_ = ycl.ReplyError(nil, "wrong request type")

return nil
Expand Down

0 comments on commit 23ac931

Please sign in to comment.