fix: 主机文件打开软链接优化 (#6432)

This commit is contained in:
2024-09-10 15:26:10 +08:00 committed by GitHub
parent 2219b3f47b
commit a0857f86b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 42 additions and 10 deletions

View File

@ -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 {

View File

@ -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',

View File

@ -1211,6 +1211,7 @@ const message = {
noNameFolder: '未命名資料夾',
noNameFile: '未命名檔案',
minimap: '縮略圖',
fileCanNotRead: '此文件不支持預覽',
},
ssh: {
autoStart: '開機自啟',

View File

@ -1215,6 +1215,7 @@ const message = {
noNameFolder: '未命名文件夹',
noNameFile: '未命名文件',
minimap: '缩略图',
fileCanNotRead: '此文件不支持预览',
},
ssh: {
autoStart: '开机自启',