MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / Create

Method Create

agent/app/service/recycle_bin.go:84–141  ·  view source on GitHub ↗
(create request.RecycleBinCreate)

Source from the content-addressed store, hash-verified

82}
83
84func (r RecycleBinService) Create(create request.RecycleBinCreate) error {
85 if files.IsProtected(create.SourcePath) {
86 return buserr.New("ErrPathNotDelete")
87 }
88 op := files.NewFileOp()
89 if !op.Stat(create.SourcePath) {
90 return buserr.New("ErrLinkPathNotFound")
91 }
92 clashRoot, err := getClashDir(create.SourcePath)
93 if err != nil {
94 return err
95 }
96 filesDir, infoDir, err := ensureTrashDirs(clashRoot)
97 if err != nil {
98 return err
99 }
100
101 deleteTime := time.Now()
102 openFile, err := op.OpenFile(create.SourcePath)
103 if err != nil {
104 return err
105 }
106 fileInfo, err := openFile.Stat()
107 _ = openFile.Close()
108 if err != nil {
109 return err
110 }
111 size := int64(0)
112 if fileInfo.IsDir() {
113 sizeF, err := op.GetDirSize(create.SourcePath)
114 if err != nil {
115 return err
116 }
117 size = int64(sizeF)
118 } else {
119 size = fileInfo.Size()
120 }
121
122 rName := allocateTrashEntryName(filesDir, infoDir, create.SourcePath)
123 info := trashInfo{
124 Path: create.SourcePath,
125 DeletionDate: deleteTime,
126 Size: size,
127 IsDir: fileInfo.IsDir(),
128 }
129 infoPath := path.Join(infoDir, rName+trashInfoSuffix)
130 if err := writeTrashInfo(infoPath, info); err != nil {
131 return err
132 }
133 targetPath := path.Join(filesDir, rName)
134 if err := op.Mv(create.SourcePath, targetPath); err != nil {
135 if rmErr := os.Remove(infoPath); rmErr != nil && !os.IsNotExist(rmErr) {
136 global.LOG.Warnf("rollback trashinfo failed for %s: %v", infoPath, rmErr)
137 }
138 return err
139 }
140 return nil
141}

Callers

nothing calls this directly

Calls 11

StatMethod · 0.95
OpenFileMethod · 0.95
GetDirSizeMethod · 0.95
MvMethod · 0.95
getClashDirFunction · 0.85
ensureTrashDirsFunction · 0.85
allocateTrashEntryNameFunction · 0.85
writeTrashInfoFunction · 0.85
IsDirMethod · 0.80
CloseMethod · 0.65
SizeMethod · 0.65

Tested by

no test coverage detected