aboutsummaryrefslogtreecommitdiff
path: root/http_server.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-10-29 01:16:58 +0700
committerShulhan <ms@kilabit.info>2023-10-29 01:16:58 +0700
commit1fa93b09807f267bba5936fe2893054b6be7ffcd (patch)
tree322bbe1ad7c15b52b7bd94e017017c30e90f0718 /http_server.go
parent6580d7bc75fcea2f62533b8db594b23d3534ac46 (diff)
downloadawwan-1fa93b09807f267bba5936fe2893054b6be7ffcd.tar.xz
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.
Diffstat (limited to 'http_server.go')
-rw-r--r--http_server.go20
1 files changed, 14 insertions, 6 deletions
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": <boolean>, 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)