From b6c873f22d8b6a3d00812fdf4a59915d60ddc3cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=98=AD?= <81747598+lan-yonghui@users.noreply.github.com>
Date: Tue, 10 Sep 2024 11:46:08 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=BB=E6=9C=BA=E6=96=87=E4=BB=B6?=
 =?UTF-8?q?=E7=9A=84=E8=B7=AF=E5=BE=84=E6=A0=8F=E8=B7=AF=E5=BE=84=20Bug=20?=
 =?UTF-8?q?=E8=A7=A3=E5=86=B3=20(#6428)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Refs #6310
---
 backend/app/service/file.go                   |  6 +++-
 .../src/views/host/file-management/index.vue  | 32 ++++++-------------
 2 files changed, 14 insertions(+), 24 deletions(-)

diff --git a/backend/app/service/file.go b/backend/app/service/file.go
index 7ae96bedb..9c401a4ef 100644
--- a/backend/app/service/file.go
+++ b/backend/app/service/file.go
@@ -62,9 +62,13 @@ func NewIFileService() IFileService {
 
 func (f *FileService) GetFileList(op request.FileOption) (response.FileInfo, error) {
 	var fileInfo response.FileInfo
-	if _, err := os.Stat(op.Path); err != nil && os.IsNotExist(err) {
+	data, err := os.Stat(op.Path)
+	if err != nil && os.IsNotExist(err) {
 		return fileInfo, nil
 	}
+	if !data.IsDir() {
+		op.FileOption.Path = filepath.Dir(op.FileOption.Path)
+	}
 	info, err := files.NewFileInfo(op.FileOption)
 	if err != nil {
 		return fileInfo, err
diff --git a/frontend/src/views/host/file-management/index.vue b/frontend/src/views/host/file-management/index.vue
index 0cd687f8f..5ddc38298 100644
--- a/frontend/src/views/host/file-management/index.vue
+++ b/frontend/src/views/host/file-management/index.vue
@@ -724,40 +724,22 @@ const top = () => {
 };
 
 const jump = async (url: string) => {
-    const fileName = url.substring(url.lastIndexOf('/') + 1);
-    let filePath = url.substring(0, url.lastIndexOf('/') + 1);
-    if (!url.includes('.')) {
-        filePath = url;
-    }
     history.splice(pointer + 1);
     history.push(url);
     pointer = history.length - 1;
 
-    const oldUrl = req.path;
-    const oldPageSize = req.pageSize;
-    // reset search params before exec jump
-    Object.assign(req, initData());
-    req.path = filePath;
-    req.containSub = false;
-    req.search = '';
-    req.pageSize = oldPageSize;
+    const { path: oldUrl, pageSize: oldPageSize } = req;
+    Object.assign(req, initData(), { path: url, containSub: false, search: '', pageSize: oldPageSize });
     let searchResult = await searchFile();
-
-    globalStore.setLastFilePath(req.path);
     // check search result,the file is exists?
     if (!searchResult.data.path) {
         req.path = oldUrl;
+        globalStore.setLastFilePath(req.path);
         MsgWarning(i18n.global.t('commons.res.notFound'));
         return;
     }
-    if (fileName && fileName.length > 1 && fileName.includes('.')) {
-        const fileData = searchResult.data.items.filter((item) => item.name === fileName);
-        if (fileData && fileData.length === 1) {
-            openView(fileData[0]);
-        } else {
-            MsgWarning(i18n.global.t('commons.res.notFound'));
-        }
-    }
+    req.path = searchResult.data.path;
+    globalStore.setLastFilePath(req.path);
     handleSearchResult(searchResult);
     getPaths(req.path);
     nextTick(function () {
@@ -896,6 +878,10 @@ const openView = (item: File.File) => {
 };
 
 const openPreview = (item: File.File, fileType: string) => {
+    if (item.mode.toString() == '-' && item.user == '-' && item.group == '-') {
+        MsgWarning(i18n.global.t('file.fileCanNotRead'));
+        return;
+    }
     filePreview.path = item.isSymlink ? item.linkPath : item.path;
     filePreview.name = item.name;
     filePreview.extension = item.extension;