Skip to content

Commit abd1581

Browse files
authored
fix: enhance file and trash services with metadata validation (#12529)
* feat: Enhance file and recycle bin services with metadata handling and validation * refactor: Rename recycle bin metadata handling to trash info and update related functions * refactor: Remove orphan trash info pruning logic and related map usage in recycle bin service
1 parent cd30ec7 commit abd1581

2 files changed

Lines changed: 342 additions & 37 deletions

File tree

agent/app/service/file.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,12 @@ func (f *FileService) buildChildNode(childNode *response.FileTree, fileInfo *fil
230230
return f.buildFileTree(childNode, subInfo.Items, op, level-1)
231231
}
232232

233+
func hasInvalidFileName(fullPath string) bool {
234+
return files.IsInvalidChar(filepath.Base(fullPath))
235+
}
236+
233237
func (f *FileService) Create(op request.FileCreate) error {
234-
if files.IsInvalidChar(op.Path) {
238+
if hasInvalidFileName(op.Path) {
235239
return buserr.New("ErrInvalidChar")
236240
}
237241
fo := files.NewFileOp()
@@ -301,6 +305,9 @@ func (f *FileService) Delete(op request.FileDelete) error {
301305
if err != nil {
302306
return err
303307
}
308+
if err := cleanupTrashInfoByEntryPath(op.Path); err != nil {
309+
global.LOG.Warnf("cleanup trashinfo failed for %s: %v", op.Path, err)
310+
}
304311
f.cleanupPermanentDeleteHistory(historyTargets)
305312
return nil
306313
}
@@ -330,13 +337,19 @@ func (f *FileService) BatchDelete(op request.FileBatchDelete) error {
330337
if err := fo.DeleteDir(file); err != nil {
331338
return err
332339
}
340+
if err := cleanupTrashInfoByEntryPath(file); err != nil {
341+
global.LOG.Warnf("cleanup trashinfo failed for %s: %v", file, err)
342+
}
333343
f.cleanupPermanentDeleteHistory(targets)
334344
}
335345
} else {
336346
for _, file := range op.Paths {
337347
if err := fo.DeleteFile(file); err != nil {
338348
return err
339349
}
350+
if err := cleanupTrashInfoByEntryPath(file); err != nil {
351+
global.LOG.Warnf("cleanup trashinfo failed for %s: %v", file, err)
352+
}
340353
f.cleanupPermanentDeleteHistory([]string{file})
341354
}
342355
}
@@ -560,7 +573,7 @@ func (f *FileService) SaveContent(edit request.FileEdit) error {
560573
}
561574

562575
func (f *FileService) ChangeName(req request.FileRename) error {
563-
if files.IsInvalidChar(req.NewName) {
576+
if hasInvalidFileName(req.NewName) {
564577
return buserr.New("ErrInvalidChar")
565578
}
566579
fo := files.NewFileOp()

0 commit comments

Comments
 (0)