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

Function writeTrashInfo

agent/app/service/recycle_bin.go:266–294  ·  view source on GitHub ↗
(dstPath string, info trashInfo)

Source from the content-addressed store, hash-verified

264}
265
266func writeTrashInfo(dstPath string, info trashInfo) error {
267 cfg := ini.Empty()
268 section, err := cfg.NewSection(trashInfoSection)
269 if err != nil {
270 return err
271 }
272 if _, err := section.NewKey("Path", url.PathEscape(info.Path)); err != nil {
273 return err
274 }
275 if _, err := section.NewKey("DeletionDate", info.DeletionDate.Format(trashInfoTimeLayout)); err != nil {
276 return err
277 }
278 if _, err := section.NewKey("Size", strconv.FormatInt(info.Size, 10)); err != nil {
279 return err
280 }
281 if _, err := section.NewKey("IsDir", strconv.FormatBool(info.IsDir)); err != nil {
282 return err
283 }
284
285 var buf bytes.Buffer
286 if _, err := cfg.WriteTo(&buf); err != nil {
287 return err
288 }
289 tmp := dstPath + ".tmp"
290 if err := os.WriteFile(tmp, buf.Bytes(), constant.FilePerm); err != nil {
291 return err
292 }
293 return os.Rename(tmp, dstPath)
294}
295
296func readTrashInfo(srcPath string) (*trashInfo, error) {
297 cfg, err := ini.Load(srcPath)

Callers 1

CreateMethod · 0.85

Calls 4

WriteFileMethod · 0.80
RenameMethod · 0.80
FormatMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected