Commit 7347a112 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'jv-eager-delete' into 'master'

Eagerly delete private tempfiles

See merge request gitlab-org/gitlab-workhorse!526
parents 5d4f889e 30d9d589
......@@ -21,6 +21,10 @@ func newCache(tempDir, filename string, data interface{}) (*cache, error) {
return nil, err
}
if err := os.Remove(f.Name()); err != nil {
return nil, err
}
return &cache{file: f, chunkSize: int64(binary.Size(data))}, nil
}
......@@ -41,10 +45,7 @@ func (c *cache) Entry(id Id, data interface{}) error {
}
func (c *cache) Close() error {
return combineErrors(
c.file.Close(),
os.Remove(c.file.Name()),
)
return c.file.Close()
}
func (c *cache) setOffset(id Id) error {
......
......@@ -42,6 +42,10 @@ func NewHovers(tempDir string) (*Hovers, error) {
return nil, err
}
if err := os.Remove(file.Name()); err != nil {
return nil, err
}
offsets, err := newCache(tempDir, "hovers-indexes", Offset{})
if err != nil {
return nil, err
......@@ -91,7 +95,6 @@ func (h *Hovers) For(refId Id) json.RawMessage {
func (h *Hovers) Close() error {
return combineErrors(
h.File.Close(),
os.Remove(h.File.Name()),
h.Offsets.Close(),
)
}
......
......@@ -68,21 +68,28 @@ func openZipReader(reader io.Reader, tempDir string) (io.Reader, error) {
if err != nil {
return nil, err
}
defer os.Remove(tempFile.Name())
if _, err := io.Copy(tempFile, reader); err != nil {
if err := os.Remove(tempFile.Name()); err != nil {
return nil, err
}
zr, err := zip.OpenReader(tempFile.Name())
size, err := io.Copy(tempFile, reader)
if err != nil {
return nil, err
}
f := zr.File[0]
if f == nil {
return nil, errors.New("invalid zip file")
if _, err := tempFile.Seek(0, io.SeekStart); err != nil {
return nil, err
}
zr, err := zip.NewReader(tempFile, size)
if err != nil {
return nil, err
}
if len(zr.File) == 0 {
return nil, errors.New("empty zip file")
}
return f.Open()
return zr.File[0].Open()
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment