MCPcopy Create free account
hub / github.com/cloudreve/cloudreve / Delete

Method Delete

service/admin/file.go:368–395  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

366)
367
368func (s *BatchFileService) Delete(c *gin.Context) error {
369 dep := dependency.FromContext(c)
370 fileClient := dep.FileClient()
371
372 ctx := context.WithValue(c, inventory.LoadFileEntity{}, true)
373 files, _, err := fileClient.GetByIDs(ctx, s.IDs, 0)
374 if err != nil {
375 return serializer.NewError(serializer.CodeDBError, "Failed to get files", err)
376 }
377
378 fc, tx, ctx, err := inventory.WithTx(c, fileClient)
379 if err != nil {
380 return serializer.NewError(serializer.CodeDBError, "Failed to start transaction", err)
381 }
382
383 _, diff, err := fc.Delete(ctx, files, nil)
384 if err != nil {
385 _ = inventory.Rollback(tx)
386 return serializer.NewError(serializer.CodeDBError, "Failed to delete files", err)
387 }
388
389 tx.AppendStorageDiff(diff)
390 if err := inventory.CommitWithStorageDiff(ctx, tx, dep.Logger(), dep.UserClient()); err != nil {
391 return serializer.NewError(serializer.CodeDBError, "Failed to commit transaction", err)
392 }
393
394 return nil
395}
396
397const (
398 entityUserCondition = "entity_user"

Callers

nothing calls this directly

Calls 11

FromContextFunction · 0.92
NewErrorFunction · 0.92
WithTxFunction · 0.92
RollbackFunction · 0.92
CommitWithStorageDiffFunction · 0.92
AppendStorageDiffMethod · 0.80
FileClientMethod · 0.65
GetByIDsMethod · 0.65
DeleteMethod · 0.65
LoggerMethod · 0.65
UserClientMethod · 0.65

Tested by

no test coverage detected