@@ -89,7 +89,7 @@ func (b *backend) Open(name string) (fs.File, error) {
8989 }
9090 if resp .StatusCode < 200 || resp .StatusCode >= 300 {
9191 _ , _ = io .Copy (io .Discard , resp .Body )
92- resp .Body .Close ()
92+ _ = resp .Body .Close ()
9393 if err := statusError (resp .StatusCode ); err != nil {
9494 return nil , fmt .Errorf ("failed to open %q: %s: %w" , u , resp .Status , err )
9595 }
@@ -144,20 +144,19 @@ func (b *backend) Remove(name string) error {
144144 if err != nil {
145145 return fmt .Errorf ("failed to remove %q: %w" , u , err )
146146 }
147+ _ , _ = io .Copy (io .Discard , resp .Body )
148+ _ = resp .Body .Close ()
147149 if resp .StatusCode < 200 || resp .StatusCode >= 300 {
148- resp .Body .Close ()
149150 return fmt .Errorf ("failed to remove %q: %s" , u , resp .Status )
150151 }
151- _ , _ = io .Copy (io .Discard , resp .Body )
152- resp .Body .Close ()
153152 return nil
154153}
155154
156155// Rename implements gocache.DiskDirFS.
157156//
158157// It requires the server to support the WebDAV MOVE method using an absolute
159158// path (but not an absolute URL) for the Destination.
160- func (b * backend ) Rename (oldpath string , newpath string ) error {
159+ func (b * backend ) Rename (oldpath , newpath string ) error {
161160 u := b .fullURL (oldpath )
162161 newURL := b .fullURL (newpath )
163162 req , err := http .NewRequest ("MOVE" , u .String (), nil )
@@ -173,12 +172,11 @@ func (b *backend) Rename(oldpath string, newpath string) error {
173172 if err != nil {
174173 return fmt .Errorf ("failed to rename %q to %q: %w" , u , newURL , err )
175174 }
175+ _ , _ = io .Copy (io .Discard , resp .Body )
176+ _ = resp .Body .Close ()
176177 if resp .StatusCode < 200 || resp .StatusCode >= 300 {
177- resp .Body .Close ()
178178 return fmt .Errorf ("failed to rename %q to %q: %s" , u , newURL , resp .Status )
179179 }
180- _ , _ = io .Copy (io .Discard , resp .Body )
181- resp .Body .Close ()
182180 return nil
183181}
184182
@@ -194,7 +192,8 @@ func (b *backend) Stat(name string) (fs.FileInfo, error) {
194192 return nil , fmt .Errorf ("failed to stat %q: %w" , u , err )
195193 }
196194 if resp .StatusCode < 200 || resp .StatusCode >= 300 {
197- resp .Body .Close ()
195+ _ , _ = io .Copy (io .Discard , resp .Body )
196+ _ = resp .Body .Close ()
198197 return nil , fmt .Errorf ("failed to stat %q: %s" , u , resp .Status )
199198 }
200199 return & readerInfo {resp : resp }, nil
0 commit comments