Skip to content

Commit

Permalink
Add support for cozy-stack files exec 'rm -f file' (#4148)
Browse files Browse the repository at this point in the history
  • Loading branch information
nono authored Oct 4, 2023
2 parents 9037040 + 4a968b1 commit 9001722
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions client/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
"path"
"path/filepath"
"strings"
"time"

"github.com/cozy/cozy-stack/client/request"
Expand Down Expand Up @@ -357,6 +358,28 @@ func (c *Client) RestoreByPath(name string) error {
return c.RestoreByID(doc.ID)
}

// PermanentDeleteByID is used to delete a file or directory specified by its
// ID, not just putting it in the trash
func (c *Client) PermanentDeleteByID(id string) error {
_, err := c.Req(&request.Options{
Method: "PATCH",
Path: "/files/" + url.PathEscape(id),
Body: strings.NewReader(`{"data": {"attributes": {"permanent_delete": true}}}`),
NoResponse: true,
})
return err
}

// PermanentDeleteByPath is used to delete a file or directory specified by its
// path, not just putting it in the trash
func (c *Client) PermanentDeleteByPath(name string) error {
doc, err := c.GetDirOrFileByPath(name)
if err != nil {
return err
}
return c.PermanentDeleteByID(doc.ID)
}

// WalkFn is the function type used by the walk function.
type WalkFn func(name string, doc *DirOrFile, err error) error

Expand Down
2 changes: 1 addition & 1 deletion cmd/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func mvCmd(c *client.Client, from, to string) error {

func rmCmd(c *client.Client, name string, force, recur bool) error {
if force {
return fmt.Errorf("not implemented")
return c.PermanentDeleteByPath(name)
}
return c.TrashByPath(name)
}
Expand Down

0 comments on commit 9001722

Please sign in to comment.