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

Function buildTrashDTO

agent/app/service/recycle_bin.go:380–410  ·  view source on GitHub ↗
(filesDir, infoDir string, entry os.DirEntry)

Source from the content-addressed store, hash-verified

378}
379
380func buildTrashDTO(filesDir, infoDir string, entry os.DirEntry) (*response.RecycleBinDTO, error) {
381 entryName := entry.Name()
382 infoPath := trashInfoPath(infoDir, entryName)
383 if info, err := readTrashInfo(infoPath); err == nil {
384 return trashInfoToDTO(entryName, filesDir, info), nil
385 } else if !os.IsNotExist(err) {
386 global.LOG.Warnf("read trashinfo %s failed: %v", infoPath, err)
387 }
388
389 entryPath := path.Join(filesDir, entryName)
390 fi, err := os.Stat(entryPath)
391 if err != nil {
392 return nil, err
393 }
394 size := fi.Size()
395 if fi.IsDir() {
396 if sz, sizeErr := files.NewFileOp().GetDirSize(entryPath); sizeErr == nil {
397 size = int64(sz)
398 }
399 }
400 return &response.RecycleBinDTO{
401 Name: entryName,
402 Size: clampToInt(size),
403 Type: "file",
404 DeleteTime: fi.ModTime(),
405 RName: entryName,
406 SourcePath: "",
407 IsDir: fi.IsDir(),
408 From: filesDir,
409 }, nil
410}
411
412func trashInfoToDTO(entryName, filesDir string, info *trashInfo) *response.RecycleBinDTO {
413 return &response.RecycleBinDTO{

Callers 1

collectTrashEntriesFunction · 0.85

Calls 10

trashInfoPathFunction · 0.85
readTrashInfoFunction · 0.85
trashInfoToDTOFunction · 0.85
clampToIntFunction · 0.85
IsDirMethod · 0.80
GetDirSizeMethod · 0.80
ModTimeMethod · 0.80
NameMethod · 0.65
SizeMethod · 0.65
StatMethod · 0.45

Tested by

no test coverage detected