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) info, err := appFs.Stat(op.Path)
if err != nil { if err != nil {
if os.IsNotExist(err) {
return nil, buserr.New(constant.ErrLinkPathNotFound)
}
return nil, err return nil, err
} }
@ -101,12 +104,25 @@ func NewFileInfo(op FileOption) (*FileInfo, error) {
} }
if file.IsSymlink { if file.IsSymlink {
file.LinkPath = GetSymlink(op.Path) linkPath := GetSymlink(op.Path)
targetInfo, err := appFs.Stat(file.LinkPath) if !filepath.IsAbs(linkPath) {
if err != nil { dir := filepath.Dir(op.Path)
return nil, err 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) file.Extension = filepath.Ext(file.LinkPath)
} }
if op.Expand { if op.Expand {
@ -314,12 +330,25 @@ func (f *FileInfo) processFiles(files []FileSearchInfo, option FileOption) ([]*F
file.FavoriteID = favorite.ID file.FavoriteID = favorite.ID
} }
if isSymlink { if isSymlink {
file.LinkPath = GetSymlink(fPath) linkPath := GetSymlink(fPath)
targetInfo, err := file.Fs.Stat(file.LinkPath) if !filepath.IsAbs(linkPath) {
if err != nil { dir := filepath.Dir(fPath)
return nil, err 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) file.Extension = filepath.Ext(file.LinkPath)
} }
if df.Size() > 0 { if df.Size() > 0 {

View file

@ -1277,6 +1277,7 @@ const message = {
noNameFolder: 'Untitled Folder', noNameFolder: 'Untitled Folder',
noNameFile: 'Untitled File', noNameFile: 'Untitled File',
minimap: 'Code Mini Map', minimap: 'Code Mini Map',
fileCanNotRead: 'File can not read',
}, },
ssh: { ssh: {
autoStart: 'Auto Start', autoStart: 'Auto Start',

View file

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

View file

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