From 1fa93b09807f267bba5936fe2893054b6be7ffcd Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 29 Oct 2023 01:16:58 +0700 Subject: all: remove the node when requested from HTTP API /awwan/api/fs Previously, the HTTP API for deleting node only remove the file but not the node in the memfs. This changes remove the child node from memfs, so the next refresh on directory will not contains the removed file. --- http_server.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'http_server.go') diff --git a/http_server.go b/http_server.go index 13169ad..6a7f576 100644 --- a/http_server.go +++ b/http_server.go @@ -182,9 +182,7 @@ func (httpd *httpServer) awwanApiFsGet(epr *libhttp.EndpointRequest) (resb []byt // awwanApiFsDelete an HTTP API to delete a file. // -// # Request -// -// Format, +// Request format, // // DELETE /awwan/api/fs // Content-Type: application/json @@ -194,9 +192,7 @@ func (httpd *httpServer) awwanApiFsGet(epr *libhttp.EndpointRequest) (resb []byt // "is_dir": , true if its directory. // } // -// # Response -// -// Format, +// Response format, // // Content-Type: application/json // @@ -236,6 +232,16 @@ func (httpd *httpServer) awwanApiFsDelete(epr *libhttp.EndpointRequest) (resb [] return nil, res } + var ( + basePath = path.Base(req.Path) + child = nodeParent.Child(basePath) + ) + + if child == nil { + res.Message = fmt.Sprintf(`%s: child not found %q`, logp, basePath) + return nil, res + } + sysPath = filepath.Join(nodeParent.SysPath, path.Base(req.Path)) sysPath, err = filepath.Abs(sysPath) if err != nil { @@ -254,6 +260,8 @@ func (httpd *httpServer) awwanApiFsDelete(epr *libhttp.EndpointRequest) (resb [] return nil, res } + _ = httpd.memfsBase.RemoveChild(nodeParent, child) + res.Code = http.StatusOK res.Message = fmt.Sprintf("%s: %q has been removed", logp, sysPath) -- cgit v1.3