From cd29cbc4f5533e11453f1aa157c179d22a26b210 Mon Sep 17 00:00:00 2001 From: dukai Date: Wed, 28 May 2025 16:41:55 +0800 Subject: [PATCH] Update: update log --- api_directory.go | 13 +++++++------ api_file.go | 6 +++--- engine/filesystem_manager.go | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/api_directory.go b/api_directory.go index f801758..dd07719 100644 --- a/api_directory.go +++ b/api_directory.go @@ -77,6 +77,7 @@ func (s *Service) HandleListDirectory( result := ListResult{ MoreAvailable: moreAvailable, IsEmptyFolder: len(rawEntries) == 0, + LastFileName: lastFileName, } if len(rawEntries) > 0 { @@ -91,8 +92,8 @@ func (s *Service) HandleListDirectory( S3Key: e.S3Key, } } + result.Entries = entries - result.LastFileName = lastFileName } 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 { 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() @@ -131,8 +132,8 @@ func (s *Service) HandleRenameDirectory( oldPath := utils.FullPath(srcPath) newPath := utils.FullPath(dstPath) 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) - return resp.InternalServerError("rename dir is failed, " + err.Error()) + logger.Error("move dir %s => %s: %v", params.SrcPath, params.DstPath, err) + return resp.InternalServerError("move directory failed, " + err.Error()) } return resp.NoContent() @@ -150,8 +151,8 @@ func (s *Service) HandleCopyDirectory( oldPath := utils.FullPath(srcPath) newPath := utils.FullPath(dstPath) 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) - return resp.InternalServerError("copy dir is failed, " + err.Error()) + logger.Error("copy dir %s => %s: %v", params.SrcPath, params.DstPath, err) + return resp.InternalServerError("copy directory failed, " + err.Error()) } return resp.NoContent() diff --git a/api_file.go b/api_file.go index 9394bdb..c9aa88d 100644 --- a/api_file.go +++ b/api_file.go @@ -137,8 +137,8 @@ func (s *Service) HandleRenameFile( err := s.FileSystemManager.RenameFile(req.Context(), srcPath, dstPath, isDir) if err != nil { - logger.Error("rename file %s to %s: %v", srcPath, dstPath, err) - return resp.InternalServerError("rename file failed, " + err.Error()) + logger.Error("move file %s => %s: %v", srcPath, dstPath, err) + return resp.InternalServerError("move file failed, " + err.Error()) } return resp.NoContent() @@ -155,7 +155,7 @@ func (s *Service) HandleCopyFile( err := s.FileSystemManager.CopyFile(req.Context(), srcPath, dstPath, isDir) 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()) } diff --git a/engine/filesystem_manager.go b/engine/filesystem_manager.go index a286f86..a5996a8 100644 --- a/engine/filesystem_manager.go +++ b/engine/filesystem_manager.go @@ -3,6 +3,7 @@ package engine import ( "context" "fmt" + "gosvc/logger" "io" "sync" "time" @@ -65,11 +66,13 @@ func (f *FileSystemManager) MakeDirectory(ctx context.Context, path utils.FullPa f.Lock() defer f.Unlock() + logger.Info("making directory => %s", path) + if string(path) == "/" { 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) } @@ -92,6 +95,8 @@ func (f *FileSystemManager) ListDirectoryEntries(ctx context.Context, p utils.Fu f.RLock() 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 { entries = append(entries, entry) return true @@ -127,6 +132,8 @@ func (f *FileSystemManager) CreateFile(ctx context.Context, path utils.FullPath, f.Lock() defer f.Unlock() + logger.Info("uploading file => %s", path) + if string(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() defer f.RUnlock() + logger.Info("downloading file => %s", path) + entry, err := f.FindEntry(ctx, path) if err != nil { 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() defer f.Unlock() + logger.Info("deleting file => %s", path) + if string(path) == "/" { return fmt.Errorf("cannot delete root") } @@ -216,6 +227,8 @@ func (f *FileSystemManager) RenameFile(ctx context.Context, srcPath, dstPath uti f.Lock() defer f.Unlock() + logger.Info("moving file %s => %s", srcPath, dstPath) + if string(srcPath) == "/" || string(dstPath) == "/" { return fmt.Errorf("cannot rename root") } @@ -261,6 +274,8 @@ func (f *FileSystemManager) CopyFile(ctx context.Context, srcPath, dstPath utils f.Lock() defer f.Unlock() + logger.Info("copying file %s => %s", srcPath, dstPath) + if string(srcPath) == "/" || string(dstPath) == "/" { return fmt.Errorf("cannot copy root") }