|
|
@@ -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 { |
|
|
|