Update: update log

This commit is contained in:
dukai 2025-05-28 16:41:55 +08:00
parent 7b4f4b389d
commit cd29cbc4f5
3 changed files with 26 additions and 10 deletions

View File

@ -77,6 +77,7 @@ func (s *Service) HandleListDirectory(
result := ListResult{ result := ListResult{
MoreAvailable: moreAvailable, MoreAvailable: moreAvailable,
IsEmptyFolder: len(rawEntries) == 0, IsEmptyFolder: len(rawEntries) == 0,
LastFileName: lastFileName,
} }
if len(rawEntries) > 0 { if len(rawEntries) > 0 {
@ -91,8 +92,8 @@ func (s *Service) HandleListDirectory(
S3Key: e.S3Key, S3Key: e.S3Key,
} }
} }
result.Entries = entries result.Entries = entries
result.LastFileName = lastFileName
} }
return resp.OK(result).JSON() return resp.OK(result).JSON()
@ -113,7 +114,7 @@ func (s *Service) HandleDeleteDirectory(
if err := s.FileSystemManager.DeleteDirectory(req.Context(), utils.FullPath(newPath), isDir, false); err != nil { if err := s.FileSystemManager.DeleteDirectory(req.Context(), utils.FullPath(newPath), isDir, false); err != nil {
logger.Error("del dir %s: %v", path, err) logger.Error("del dir %s: %v", path, err)
return resp.InternalServerError("delete directory is failed, " + err.Error()) return resp.InternalServerError("delete directory failed, " + err.Error())
} }
return resp.NoContent() return resp.NoContent()
@ -131,8 +132,8 @@ func (s *Service) HandleRenameDirectory(
oldPath := utils.FullPath(srcPath) oldPath := utils.FullPath(srcPath)
newPath := utils.FullPath(dstPath) newPath := utils.FullPath(dstPath)
if err := s.FileSystemManager.RenameDirectory(req.Context(), oldPath, newPath, isDir); err != nil { if err := s.FileSystemManager.RenameDirectory(req.Context(), oldPath, newPath, isDir); err != nil {
logger.Error("rename dir %s to %s: %v", params.SrcPath, params.DstPath, err) logger.Error("move dir %s => %s: %v", params.SrcPath, params.DstPath, err)
return resp.InternalServerError("rename dir is failed, " + err.Error()) return resp.InternalServerError("move directory failed, " + err.Error())
} }
return resp.NoContent() return resp.NoContent()
@ -150,8 +151,8 @@ func (s *Service) HandleCopyDirectory(
oldPath := utils.FullPath(srcPath) oldPath := utils.FullPath(srcPath)
newPath := utils.FullPath(dstPath) newPath := utils.FullPath(dstPath)
if err := s.FileSystemManager.CopyDirectory(req.Context(), oldPath, newPath, isDir); err != nil { if err := s.FileSystemManager.CopyDirectory(req.Context(), oldPath, newPath, isDir); err != nil {
logger.Error("copy dir %s to %s: %v", params.SrcPath, params.DstPath, err) logger.Error("copy dir %s => %s: %v", params.SrcPath, params.DstPath, err)
return resp.InternalServerError("copy dir is failed, " + err.Error()) return resp.InternalServerError("copy directory failed, " + err.Error())
} }
return resp.NoContent() return resp.NoContent()

View File

@ -137,8 +137,8 @@ func (s *Service) HandleRenameFile(
err := s.FileSystemManager.RenameFile(req.Context(), srcPath, dstPath, isDir) err := s.FileSystemManager.RenameFile(req.Context(), srcPath, dstPath, isDir)
if err != nil { if err != nil {
logger.Error("rename file %s to %s: %v", srcPath, dstPath, err) logger.Error("move file %s => %s: %v", srcPath, dstPath, err)
return resp.InternalServerError("rename file failed, " + err.Error()) return resp.InternalServerError("move file failed, " + err.Error())
} }
return resp.NoContent() return resp.NoContent()
@ -155,7 +155,7 @@ func (s *Service) HandleCopyFile(
err := s.FileSystemManager.CopyFile(req.Context(), srcPath, dstPath, isDir) err := s.FileSystemManager.CopyFile(req.Context(), srcPath, dstPath, isDir)
if err != nil { if err != nil {
logger.Error("copy %s to %s: %v", srcPath, dstPath, err) logger.Error("copy file %s => %s: %v", srcPath, dstPath, err)
return resp.InternalServerError("copy file failed, " + err.Error()) return resp.InternalServerError("copy file failed, " + err.Error())
} }

View File

@ -3,6 +3,7 @@ package engine
import ( import (
"context" "context"
"fmt" "fmt"
"gosvc/logger"
"io" "io"
"sync" "sync"
"time" "time"
@ -65,11 +66,13 @@ func (f *FileSystemManager) MakeDirectory(ctx context.Context, path utils.FullPa
f.Lock() f.Lock()
defer f.Unlock() defer f.Unlock()
logger.Info("making directory => %s", path)
if string(path) == "/" { if string(path) == "/" {
return nil return nil
} }
if entry, _ := f.FindEntry(ctx, path); entry != nil { if entry, err := f.FindEntry(ctx, path); err == nil && entry != nil {
return fmt.Errorf("directory %s already exists", path) return fmt.Errorf("directory %s already exists", path)
} }
@ -92,6 +95,8 @@ func (f *FileSystemManager) ListDirectoryEntries(ctx context.Context, p utils.Fu
f.RLock() f.RLock()
defer f.RUnlock() defer f.RUnlock()
logger.Info("listing directory %s => %s %t %d", p, startFileName, inclusive, limit)
lastFileName, err = f.StreamListDirectoryEntries(ctx, p, startFileName, inclusive, limit+1, func(entry *utils.Entry) bool { lastFileName, err = f.StreamListDirectoryEntries(ctx, p, startFileName, inclusive, limit+1, func(entry *utils.Entry) bool {
entries = append(entries, entry) entries = append(entries, entry)
return true return true
@ -127,6 +132,8 @@ func (f *FileSystemManager) CreateFile(ctx context.Context, path utils.FullPath,
f.Lock() f.Lock()
defer f.Unlock() defer f.Unlock()
logger.Info("uploading file => %s", path)
if string(path) == "/" { if string(path) == "/" {
return fmt.Errorf("cannot create file %s", path) return fmt.Errorf("cannot create file %s", path)
} }
@ -169,6 +176,8 @@ func (f *FileSystemManager) DownloadFile(ctx context.Context, path utils.FullPat
f.RLock() f.RLock()
defer f.RUnlock() defer f.RUnlock()
logger.Info("downloading file => %s", path)
entry, err := f.FindEntry(ctx, path) entry, err := f.FindEntry(ctx, path)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("find entry failed: %v", err) return nil, nil, fmt.Errorf("find entry failed: %v", err)
@ -190,6 +199,8 @@ func (f *FileSystemManager) DeleteFile(ctx context.Context, path utils.FullPath,
f.Lock() f.Lock()
defer f.Unlock() defer f.Unlock()
logger.Info("deleting file => %s", path)
if string(path) == "/" { if string(path) == "/" {
return fmt.Errorf("cannot delete root") return fmt.Errorf("cannot delete root")
} }
@ -216,6 +227,8 @@ func (f *FileSystemManager) RenameFile(ctx context.Context, srcPath, dstPath uti
f.Lock() f.Lock()
defer f.Unlock() defer f.Unlock()
logger.Info("moving file %s => %s", srcPath, dstPath)
if string(srcPath) == "/" || string(dstPath) == "/" { if string(srcPath) == "/" || string(dstPath) == "/" {
return fmt.Errorf("cannot rename root") return fmt.Errorf("cannot rename root")
} }
@ -261,6 +274,8 @@ func (f *FileSystemManager) CopyFile(ctx context.Context, srcPath, dstPath utils
f.Lock() f.Lock()
defer f.Unlock() defer f.Unlock()
logger.Info("copying file %s => %s", srcPath, dstPath)
if string(srcPath) == "/" || string(dstPath) == "/" { if string(srcPath) == "/" || string(dstPath) == "/" {
return fmt.Errorf("cannot copy root") return fmt.Errorf("cannot copy root")
} }