diff options
| author | Shulhan <ms@kilabit.info> | 2023-10-29 01:16:58 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-10-29 01:16:58 +0700 |
| commit | 1fa93b09807f267bba5936fe2893054b6be7ffcd (patch) | |
| tree | 322bbe1ad7c15b52b7bd94e017017c30e90f0718 | |
| parent | 6580d7bc75fcea2f62533b8db594b23d3534ac46 (diff) | |
| download | awwan-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.
| -rw-r--r-- | go.mod | 2 | ||||
| -rw-r--r-- | go.sum | 4 | ||||
| -rw-r--r-- | http_server.go | 20 |
3 files changed, 17 insertions, 9 deletions
@@ -8,7 +8,7 @@ go 1.20 require ( git.sr.ht/~shulhan/ciigo v0.10.0 github.com/evanw/esbuild v0.19.5 - github.com/shuLhan/share v0.50.1-0.20231024141832-cea29b1890e2 + github.com/shuLhan/share v0.50.1-0.20231028174653-72e51cb46061 ) require ( @@ -4,8 +4,8 @@ git.sr.ht/~shulhan/ciigo v0.10.0 h1:s1SJ3/NzBcbOLmEZ4z1Cx9Vf7ZdDIvm45b7KMCZKzEY= git.sr.ht/~shulhan/ciigo v0.10.0/go.mod h1:cG6av+ywJZZp96F43kmLB2QWjm2hYiahbsbeTX/vlgk= github.com/evanw/esbuild v0.19.5 h1:9ildZqajUJzDAwNf9MyQsLh2RdDRKTq3kcyyzhE39us= github.com/evanw/esbuild v0.19.5/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48= -github.com/shuLhan/share v0.50.1-0.20231024141832-cea29b1890e2 h1:cFCbkJ0iwOmME8GvTn8Yd+JZc6XO2d3zUaIM+7Zp7rU= -github.com/shuLhan/share v0.50.1-0.20231024141832-cea29b1890e2/go.mod h1:dUE7xqEzT8HZRy8vvfFzrFJ+6a6chXwaPmC4hYB68QU= +github.com/shuLhan/share v0.50.1-0.20231028174653-72e51cb46061 h1:e9GMD4wA6YePnh2wLMFU/wYSoVlFWSA/ZFskf03Lzqo= +github.com/shuLhan/share v0.50.1-0.20231028174653-72e51cb46061/go.mod h1:dUE7xqEzT8HZRy8vvfFzrFJ+6a6chXwaPmC4hYB68QU= github.com/yuin/goldmark v1.5.6 h1:COmQAWTCcGetChm3Ig7G/t8AFAN00t+o8Mt4cf7JpwA= github.com/yuin/goldmark v1.5.6/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc= 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) |
