Ensure files are closed after they are done being used
This commit is contained in:
parent
43b7aa2536
commit
e9b8b11fec
|
@ -95,6 +95,7 @@ func getDownloadFile(c *gin.Context) {
|
||||||
middleware.CaptureAndAbort(c, err)
|
middleware.CaptureAndAbort(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
c.Header("Content-Length", strconv.Itoa(int(st.Size())))
|
c.Header("Content-Length", strconv.Itoa(int(st.Size())))
|
||||||
c.Header("Content-Disposition", "attachment; filename="+strconv.Quote(st.Name()))
|
c.Header("Content-Disposition", "attachment; filename="+strconv.Quote(st.Name()))
|
||||||
|
|
|
@ -85,6 +85,7 @@ func (b *LocalBackup) Restore(ctx context.Context, _ io.Reader, callback Restore
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
var reader io.Reader = f
|
var reader io.Reader = f
|
||||||
// Steal the logic we use for making backups which will be applied when restoring
|
// Steal the logic we use for making backups which will be applied when restoring
|
||||||
|
|
|
@ -148,7 +148,7 @@ func (fs *Filesystem) DecompressFileUnsafe(ctx context.Context, dir string, file
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// TODO: defer file close?
|
defer f.Close()
|
||||||
|
|
||||||
// Identify the type of archive we are dealing with.
|
// Identify the type of archive we are dealing with.
|
||||||
format, input, err := archiver.Identify(filepath.Base(file), f)
|
format, input, err := archiver.Identify(filepath.Base(file), f)
|
||||||
|
|
|
@ -92,6 +92,9 @@ func (fs *Filesystem) Touch(p string, flag int) (*os.File, error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
if f != nil {
|
||||||
|
_ = f.Close()
|
||||||
|
}
|
||||||
// If the error is not because it doesn't exist then we just need to bail at this point.
|
// If the error is not because it doesn't exist then we just need to bail at this point.
|
||||||
if !errors.Is(err, os.ErrNotExist) {
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
return nil, errors.Wrap(err, "server/filesystem: touch: failed to open file handle")
|
return nil, errors.Wrap(err, "server/filesystem: touch: failed to open file handle")
|
||||||
|
@ -114,6 +117,7 @@ func (fs *Filesystem) Touch(p string, flag int) (*os.File, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "server/filesystem: touch: failed to open file with wait")
|
return nil, errors.Wrap(err, "server/filesystem: touch: failed to open file with wait")
|
||||||
}
|
}
|
||||||
|
_ = f.Close()
|
||||||
_ = fs.Chown(cleaned)
|
_ = fs.Chown(cleaned)
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user