@@ -2,10 +2,11 @@ package handles
22
33import (
44 "fmt"
5- "github.com/alist-org/alist/v3/internal/task"
65 "io"
76 stdpath "path"
87
8+ "github.com/alist-org/alist/v3/internal/task"
9+
910 "github.com/alist-org/alist/v3/internal/errs"
1011 "github.com/alist-org/alist/v3/internal/fs"
1112 "github.com/alist-org/alist/v3/internal/model"
@@ -213,6 +214,22 @@ type RenameReq struct {
213214 Overwrite bool `json:"overwrite"`
214215}
215216
217+ func canRenamePath (c * gin.Context , reqPath string ) bool {
218+ meta , err := op .GetNearestMeta (reqPath )
219+ if err != nil {
220+ if ! errors .Is (errors .Cause (err ), errs .MetaNotFound ) {
221+ common .ErrorResp (c , err , 500 , true )
222+ return false
223+ }
224+ return true
225+ }
226+ if meta != nil && meta .Password != "" && common .IsApply (meta .Path , reqPath , meta .PSub ) {
227+ common .ErrorStrResp (c , "Path is password-protected and cannot be renamed." , 403 )
228+ return false
229+ }
230+ return true
231+ }
232+
216233func FsRename (c * gin.Context ) {
217234 var req RenameReq
218235 if err := c .ShouldBind (& req ); err != nil {
@@ -229,6 +246,9 @@ func FsRename(c *gin.Context) {
229246 common .ErrorResp (c , errs .PermissionDenied , 403 )
230247 return
231248 }
249+ if ! canRenamePath (c , reqPath ) {
250+ return
251+ }
232252 perm := common .MergeRolePermissions (user , reqPath )
233253 if ! common .HasPermission (perm , common .PermRename ) {
234254 common .ErrorResp (c , errs .PermissionDenied , 403 )
0 commit comments