Skip to content

Commit

Permalink
Added logic to prepare for returning information about the file
Browse files Browse the repository at this point in the history
  • Loading branch information
datadius committed Apr 24, 2024
1 parent 8007c8b commit 4f72b51
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 20 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,17 +380,33 @@ func (a *Client) CopyFromRemotePassThru(
return
}

fileInfo := NewFileInfos()

if res.IsTime() {
timeInfo, err := res.ParseFileTime()

if err != nil {
errCh <- err
return
}

fileInfo.Update(timeInfo)

res, err = ParseResponse(r)
if err != nil {
errCh <- err
return
}

if res.IsFailure() || res.NoStandardProtocolType() {
if res.IsFailure() {
errCh <- errors.New(res.GetMessage())
return
}

if res.NoStandardProtocolType() {
errCh <- errors.New(fmt.Sprintf("Input from server doesn't follow protocol: %s", res.GetMessage()))
return
}
}

// The CHMOD message always comes before the actual data is being sent
Expand All @@ -400,6 +416,9 @@ func (a *Client) CopyFromRemotePassThru(
}

infos, err := res.ParseFileInfos()

fileInfo.Update(infos)

if err != nil {
errCh <- err
return
Expand Down
4 changes: 4 additions & 0 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ type FileInfos struct {
Mtime int64
}

func NewFileInfos() *FileInfos {
return &FileInfos{}
}

func (fileInfos *FileInfos) Update(new *FileInfos) {
if new == nil {
return
Expand Down

0 comments on commit 4f72b51

Please sign in to comment.