Implement file deletion
This commit is contained in:
@@ -79,7 +79,7 @@ func (t fileUploadState) String() string {
|
||||
|
||||
func OpenFileStore(path string) error {
|
||||
if path == "" {
|
||||
return errors.New("file store path not set")
|
||||
return errors.New("file-store not set")
|
||||
}
|
||||
|
||||
// Try to create the file store directory if it does not yet exist
|
||||
@@ -158,11 +158,23 @@ func (fu *fileUpload) save(tx *bolt.Tx) error {
|
||||
}
|
||||
|
||||
func (fu *fileUpload) delete(tx *bolt.Tx) error {
|
||||
// Replace the old paste with a new empty paste
|
||||
return (&fileUpload{
|
||||
// Remove the file in the backend
|
||||
filePath := fileStorePath(fu.ID, fu.FileName)
|
||||
if err := os.Remove(filePath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Update the file in the server
|
||||
if err := (&fileUpload{
|
||||
ID: fu.ID,
|
||||
State: fileUploadStateDeleted,
|
||||
}).save(tx)
|
||||
}).save(tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Cleanup the parent directory
|
||||
wrap := "deletion succeeded, but removing the file directory has failed"
|
||||
return errors.Wrap(os.Remove(path.Dir(filePath)), wrap)
|
||||
}
|
||||
|
||||
func (fu *fileUpload) url() *url.URL {
|
||||
|
||||
Reference in New Issue
Block a user