@@ -23,7 +23,10 @@ import (
2323 "errors"
2424 "net/http"
2525 "path"
26+ "slices"
27+ "strings"
2628
29+ gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
2730 rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
2831 provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
2932 "github.com/owncloud/reva/v2/internal/http/services/owncloud/ocdav/net"
@@ -81,6 +84,17 @@ func (s *svc) handleDelete(ctx context.Context, w http.ResponseWriter, r *http.R
8184 return http .StatusInternalServerError , errtypes .InternalError (err .Error ())
8285 }
8386
87+ sRes , err := client .Stat (ctx , & provider.StatRequest {Ref : ref })
88+ switch {
89+ case err != nil :
90+ span .RecordError (err )
91+ return http .StatusInternalServerError , err
92+ case sRes .GetStatus ().GetCode () == rpc .Code_CODE_OK :
93+ if sRes .GetInfo ().GetSpace ().GetSpaceType () == "project" && isPathInList (ctx , client , ref , ".space" , ".space/readme.md" ) {
94+ return http .StatusMethodNotAllowed , errors .New ("deleting spaces meta file is not allowed" )
95+ }
96+ }
97+
8498 res , err := client .Delete (ctx , req )
8599 switch {
86100 case err != nil :
@@ -147,3 +161,17 @@ func (s *svc) handleSpacesDelete(w http.ResponseWriter, r *http.Request, spaceID
147161
148162 return s .handleDelete (ctx , w , r , & ref )
149163}
164+
165+ func isPathInList (ctx context.Context , client gateway.GatewayAPIClient , ref * provider.Reference , paths ... string ) bool {
166+ resPath := strings .TrimPrefix (ref .GetPath (), "./" )
167+ if ref .GetResourceId ().GetOpaqueId () != "" && ref .Path == "." {
168+ gpRes , err := client .GetPath (ctx , & provider.GetPathRequest {
169+ ResourceId : ref .GetResourceId (),
170+ })
171+ if err != nil || gpRes .GetStatus ().GetCode () != rpc .Code_CODE_OK {
172+ return false
173+ }
174+ resPath = strings .TrimPrefix (gpRes .GetPath (), "/" )
175+ }
176+ return slices .Contains (paths , resPath )
177+ }
0 commit comments