From e452205c38e0fdb7cedc4b9e0f4c4f6d338f8aae Mon Sep 17 00:00:00 2001 From: Bernhard B Date: Mon, 24 Mar 2025 23:15:22 +0100 Subject: [PATCH] handle non existent attachments folder gracefully --- src/client/client.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/client/client.go b/src/client/client.go index cc45eb5..25a56e4 100644 --- a/src/client/client.go +++ b/src/client/client.go @@ -1334,15 +1334,23 @@ func (s *SignalClient) GetAccounts() ([]string, error) { func (s *SignalClient) GetAttachments() ([]string, error) { files := []string{} - err := filepath.Walk(s.signalCliConfig+"/attachments/", func(path string, info os.FileInfo, err error) error { - if info.IsDir() { + attachmentsPath := s.signalCliConfig+"/attachments/" + if _, err := os.Stat(attachmentsPath); !os.IsNotExist(err) { + err = filepath.Walk(attachmentsPath, func(path string, info os.FileInfo, err error) error { + if info.IsDir() { + return nil + } + files = append(files, filepath.Base(path)) return nil + }) + if err != nil { + return files, err } - files = append(files, filepath.Base(path)) - return nil - }) + } else { + return files, nil + } - return files, err + return files, nil } func (s *SignalClient) RemoveAttachment(attachment string) error {