From 3b14bf510e2c5471c73e19eadf1528bcba2be2a0 Mon Sep 17 00:00:00 2001 From: Data Dius <16731794+datadius@users.noreply.github.com> Date: Tue, 30 Apr 2024 22:05:05 +0200 Subject: [PATCH] made fileperm in FileInfos directly usable with os.FileMode --- protocol.go | 13 +++++++++---- tests/basic_test.go | 12 ++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/protocol.go b/protocol.go index 1c65bb5..1fa936e 100644 --- a/protocol.go +++ b/protocol.go @@ -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 @@ -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 { @@ -136,6 +136,11 @@ 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 @@ -143,7 +148,7 @@ func ParseFileInfos(message string, fileInfos *FileInfos) error { fileInfos.Update(&FileInfos{ Filename: parts[2], - Permissions: parts[0], + Permissions: uint32(permissions), Size: int64(size), }) @@ -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") } diff --git a/tests/basic_test.go b/tests/basic_test.go index f4d7ffd..038e922 100644 --- a/tests/basic_test.go +++ b/tests/basic_test.go @@ -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