Skip to content

Commit

Permalink
made fileperm in FileInfos directly usable with os.FileMode
Browse files Browse the repository at this point in the history
  • Loading branch information
datadius committed Apr 30, 2024
1 parent 6ea89a2 commit 3b14bf5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 9 additions & 4 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func ParseResponse(reader io.Reader, writer io.Writer) (*FileInfos, error) {
type FileInfos struct {
Message string
Filename string
Permissions string
Permissions uint32
Size int64
Atime int64
Mtime int64
Expand All @@ -115,7 +115,7 @@ func (fileInfos *FileInfos) Update(new *FileInfos) {
if new.Filename != "" {
fileInfos.Filename = new.Filename
}
if new.Permissions != "" {
if new.Permissions != 0 {
fileInfos.Permissions = new.Permissions
}
if new.Size != 0 {
Expand All @@ -136,14 +136,19 @@ func ParseFileInfos(message string, fileInfos *FileInfos) error {
return errors.New("unable to parse Chmod protocol")
}

permissions, err := strconv.ParseUint(parts[0][1:5], 0, 32)
if err != nil {
return err
}

size, err := strconv.Atoi(parts[1])
if err != nil {
return err
}

fileInfos.Update(&FileInfos{
Filename: parts[2],
Permissions: parts[0],
Permissions: uint32(permissions),
Size: int64(size),
})

Expand All @@ -164,7 +169,7 @@ func ParseFileTime(
if err != nil {
return errors.New("unable to parse ATime component of message")
}
mTime, err := strconv.Atoi(string(parts[2][0:10]))
mTime, err := strconv.ParseUint(string(parts[2][0:10]), 0, 32)
if err != nil {
return errors.New("unable to parse MTime component of message")
}
Expand Down
12 changes: 12 additions & 0 deletions tests/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,18 @@ func TestDownloadFileInfo(t *testing.T) {
t.Errorf("File size does not match")
}

if fileInfos.Mtime == 0 {
t.Errorf("No file mtime preserved")
}

if fileInfos.Atime == 0 {
t.Errorf("No file atime preserved")
}

if fileInfos.Permissions == 0 {
t.Errorf("No file permissions preserved")
}

}

// TestTimeoutDownload tests that a timeout error is produced if the file is not copied in the given
Expand Down

0 comments on commit 3b14bf5

Please sign in to comment.