diff --git a/backend/utils/files/fileinfo.go b/backend/utils/files/fileinfo.go index ec3af09bf..7c25ad6ca 100644 --- a/backend/utils/files/fileinfo.go +++ b/backend/utils/files/fileinfo.go @@ -72,6 +72,9 @@ func NewFileInfo(op FileOption) (*FileInfo, error) { info, err := appFs.Stat(op.Path) if err != nil { + if os.IsNotExist(err) { + return nil, buserr.New(constant.ErrLinkPathNotFound) + } return nil, err } @@ -101,12 +104,25 @@ func NewFileInfo(op FileOption) (*FileInfo, error) { } if file.IsSymlink { - file.LinkPath = GetSymlink(op.Path) - targetInfo, err := appFs.Stat(file.LinkPath) - if err != nil { - return nil, err + linkPath := GetSymlink(op.Path) + if !filepath.IsAbs(linkPath) { + dir := filepath.Dir(op.Path) + var err error + linkPath, err = filepath.Abs(filepath.Join(dir, linkPath)) + if err != nil { + return nil, err + } + } + file.LinkPath = linkPath + targetInfo, err := appFs.Stat(linkPath) + if err != nil { + file.IsDir = false + file.Mode = "-" + file.User = "-" + file.Group = "-" + } else { + file.IsDir = targetInfo.IsDir() } - file.IsDir = targetInfo.IsDir() file.Extension = filepath.Ext(file.LinkPath) } if op.Expand { @@ -314,12 +330,25 @@ func (f *FileInfo) processFiles(files []FileSearchInfo, option FileOption) ([]*F file.FavoriteID = favorite.ID } if isSymlink { - file.LinkPath = GetSymlink(fPath) - targetInfo, err := file.Fs.Stat(file.LinkPath) - if err != nil { - return nil, err + linkPath := GetSymlink(fPath) + if !filepath.IsAbs(linkPath) { + dir := filepath.Dir(fPath) + var err error + linkPath, err = filepath.Abs(filepath.Join(dir, linkPath)) + if err != nil { + return nil, err + } + } + file.LinkPath = linkPath + targetInfo, err := file.Fs.Stat(linkPath) + if err != nil { + file.IsDir = false + file.Mode = "-" + file.User = "-" + file.Group = "-" + } else { + file.IsDir = targetInfo.IsDir() } - file.IsDir = targetInfo.IsDir() file.Extension = filepath.Ext(file.LinkPath) } if df.Size() > 0 { diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 6eab83747..15d940f52 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -1277,6 +1277,7 @@ const message = { noNameFolder: 'Untitled Folder', noNameFile: 'Untitled File', minimap: 'Code Mini Map', + fileCanNotRead: 'File can not read', }, ssh: { autoStart: 'Auto Start', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 940115420..4ba5e2113 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -1211,6 +1211,7 @@ const message = { noNameFolder: '未命名資料夾', noNameFile: '未命名檔案', minimap: '縮略圖', + fileCanNotRead: '此文件不支持預覽', }, ssh: { autoStart: '開機自啟', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index ec6897c3a..d0c54518d 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -1215,6 +1215,7 @@ const message = { noNameFolder: '未命名文件夹', noNameFile: '未命名文件', minimap: '缩略图', + fileCanNotRead: '此文件不支持预览', }, ssh: { autoStart: '开机自启',