From 0ccfbe71e46a4e0477e449942f0125a9d9663ccd Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 26 Sep 2024 17:45:03 +0100 Subject: [PATCH] smb: fix panic if stat fails Before this fix the smb backend could panic if a stat call failed. This fix makes it return an error instead. It should have the side effect that we do one less stat call on upload too. Fixes #8106 --- backend/smb/smb.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/smb/smb.go b/backend/smb/smb.go index 37ac06554..ff8f40976 100644 --- a/backend/smb/smb.go +++ b/backend/smb/smb.go @@ -601,9 +601,10 @@ func (o *Object) SetModTime(ctx context.Context, t time.Time) (err error) { } fi, err := cn.smbShare.Stat(reqDir) - if err == nil { - o.statResult = fi + if err != nil { + return fmt.Errorf("SetModTime: stat: %w", err) } + o.statResult = fi return err } @@ -685,7 +686,6 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op return err } defer func() { - o.statResult, _ = cn.smbShare.Stat(filename) o.fs.putConnection(&cn) }() @@ -723,7 +723,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op return fmt.Errorf("Update Close failed: %w", err) } - // Set the modified time + // Set the modified time and also o.statResult err = o.SetModTime(ctx, src.ModTime(ctx)) if err != nil { return fmt.Errorf("Update SetModTime failed: %w", err)