From 2b2854464ffe8d4c982194f3fd30f2c19a5f1287 Mon Sep 17 00:00:00 2001 From: mstmdev Date: Thu, 10 Aug 2023 00:05:11 +0800 Subject: [PATCH] Implement read link in the file query api (#233) --- server/handler/file_api_handler.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/handler/file_api_handler.go b/server/handler/file_api_handler.go index ea95d24..a1d639d 100644 --- a/server/handler/file_api_handler.go +++ b/server/handler/file_api_handler.go @@ -18,14 +18,14 @@ import ( type fileApiHandler struct { logger log.Logger - root http.FileSystem + root http.Dir chunkSize int64 checkpointCount int hash hashutil.Hash } // NewFileApiHandlerFunc returns a gin.HandlerFunc that queries the file info -func NewFileApiHandlerFunc(logger log.Logger, root http.FileSystem, chunkSize int64, checkpointCount int, hash hashutil.Hash) gin.HandlerFunc { +func NewFileApiHandlerFunc(logger log.Logger, root http.Dir, chunkSize int64, checkpointCount int, hash hashutil.Hash) gin.HandlerFunc { return (&fileApiHandler{ logger: logger, root: root, @@ -146,7 +146,12 @@ func (h *fileApiHandler) readDir(f http.File, needHash bool, needCheckpoint bool func (h *fileApiHandler) readlink(file fs.FileInfo) string { if nsfs.IsSymlinkMode(file.Mode()) { - // TODO readlink + path := filepath.Join(string(h.root), file.Name()) + realPath, err := nsfs.Readlink(path) + if err == nil { + return realPath + } + h.logger.Error(err, "file api read link error => %s", path) return file.Name() } return "" -- GitLab