imagekit: fix potential crash in rmdir and purge

Rmdir and Purge read the response status code before checking for an
error, so a failed DeleteFolder call with no HTTP response (a network
error, or purging the root which fails validation) panicked.

Thanks to @manus-pi for finding this problem.

(cherry picked from commit e2cd9a5dfb)
This commit is contained in:
Nick Craig-Wood committed 2026-10-08 17:17:11 +01:00
1 parent 06387f878a
commit dca3902fef
1 file changed
+2 -2
+2 -2
View File
@@ -477,7 +477,7 @@ func (f *Fs) Rmdir(ctx context.Context, dir string) (err error) {
FolderPath: f.EncodePath(path.Join(f.root, dir)),
})
if res.StatusCode == http.StatusNotFound {
if res != nil && res.StatusCode == http.StatusNotFound {
return false, fs.ErrorDirNotFound
}
@@ -502,7 +502,7 @@ func (f *Fs) Purge(ctx context.Context, dir string) (err error) {
FolderPath: f.EncodePath(remote),
})
if res.StatusCode == http.StatusNotFound {
if res != nil && res.StatusCode == http.StatusNotFound {
return false, fs.ErrorDirNotFound
}