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) { ...@@ -21,6 +21,10 @@ func newCache(tempDir, filename string, data interface{}) (*cache, error) {
return nil, err return nil, err
} }
if err := os.Remove(f.Name()); err != nil {
return nil, err
}
return &cache{file: f, chunkSize: int64(binary.Size(data))}, nil return &cache{file: f, chunkSize: int64(binary.Size(data))}, nil
} }
...@@ -41,10 +45,7 @@ func (c *cache) Entry(id Id, data interface{}) error { ...@@ -41,10 +45,7 @@ func (c *cache) Entry(id Id, data interface{}) error {
} }
func (c *cache) Close() error { func (c *cache) Close() error {
return combineErrors( return c.file.Close()
c.file.Close(),
os.Remove(c.file.Name()),
)
} }
func (c *cache) setOffset(id Id) error { func (c *cache) setOffset(id Id) error {
......
...@@ -42,6 +42,10 @@ func NewHovers(tempDir string) (*Hovers, error) { ...@@ -42,6 +42,10 @@ func NewHovers(tempDir string) (*Hovers, error) {
return nil, err return nil, err
} }
if err := os.Remove(file.Name()); err != nil {
return nil, err
}
offsets, err := newCache(tempDir, "hovers-indexes", Offset{}) offsets, err := newCache(tempDir, "hovers-indexes", Offset{})
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -91,7 +95,6 @@ func (h *Hovers) For(refId Id) json.RawMessage { ...@@ -91,7 +95,6 @@ func (h *Hovers) For(refId Id) json.RawMessage {
func (h *Hovers) Close() error { func (h *Hovers) Close() error {
return combineErrors( return combineErrors(
h.File.Close(), h.File.Close(),
os.Remove(h.File.Name()),
h.Offsets.Close(), h.Offsets.Close(),
) )
} }
......
...@@ -68,21 +68,28 @@ func openZipReader(reader io.Reader, tempDir string) (io.Reader, error) { ...@@ -68,21 +68,28 @@ func openZipReader(reader io.Reader, tempDir string) (io.Reader, error) {
if err != nil { if err != nil {
return nil, err 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 return nil, err
} }
zr, err := zip.OpenReader(tempFile.Name()) size, err := io.Copy(tempFile, reader)
if err != nil { if err != nil {
return nil, err return nil, err
} }
f := zr.File[0] if _, err := tempFile.Seek(0, io.SeekStart); err != nil {
if f == nil { return nil, err
return nil, errors.New("invalid zip file") }
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