Explorar el Código

ensure localstorage does not delete more than 1 file

pull/294/head
Stefan Benten hace 4 años
padre
commit
ac84ee60cf
Se han modificado 1 ficheros con 10 adiciones y 2 borrados
  1. +10
    -2
      server/storage/local.go

+ 10
- 2
server/storage/local.go Ver fichero

@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
@@ -92,8 +93,15 @@ func (s *LocalStorage) Put(token string, filename string, reader io.Reader, meta
}

func (s *LocalStorage) Delete(token string, filename string) (err error) {
log.Printf("deleting file %s/%s/%s", s.basedir, token, filename)
return os.RemoveAll(filepath.Join(s.basedir, token))
dir := filepath.Join(s.basedir, token)
log.Printf("deleting file %s/%s/%s", dir, filename)
// ensure we do not accidentally delete more than the specified file in the folder
if files, err := ioutil.ReadDir(dir); len(files) > 2 || err != nil {
// ignore if we cannot delete the metadata file
_ = os.Remove(filepath.Join(dir, fmt.Sprintf("%s.metadata", filename)))
return os.Remove(filepath.Join(dir, filename))
}
return os.RemoveAll(dir)
}

func (s *LocalStorage) IsNotExist(err error) bool {


Cargando…
Cancelar
Guardar