Skip to content

Commit

Permalink
fix: 解决软连接被识别为文件问题 (#6400)
Browse files Browse the repository at this point in the history
Refs #5879
  • Loading branch information
lan-yonghui authored Sep 6, 2024
1 parent dd1430d commit a53fff2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions backend/utils/files/fileinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ 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
}
file.IsDir = targetInfo.IsDir()
file.Extension = filepath.Ext(file.LinkPath)
}
if op.Expand {
if err := handleExpansion(file, op); err != nil {
Expand Down Expand Up @@ -309,6 +315,12 @@ func (f *FileInfo) processFiles(files []FileSearchInfo, option FileOption) ([]*F
}
if isSymlink {
file.LinkPath = GetSymlink(fPath)
targetInfo, err := file.Fs.Stat(file.LinkPath)
if err != nil {
return nil, err
}
file.IsDir = targetInfo.IsDir()
file.Extension = filepath.Ext(file.LinkPath)
}
if df.Size() > 0 {
file.MimeType = GetMimeType(fPath)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/interface/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export namespace File {
size: number;
isDir: boolean;
isSymlink: boolean;
linkPath: boolean;
linkPath: string;
type: string;
updateTime: string;
modTime: string;
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/views/host/file-management/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -891,12 +891,12 @@ const openView = (item: File.File) => {
compress: openDeCompress,
text: () => openCodeEditor(item.path, item.extension),
};
return actionMap[fileType] ? actionMap[fileType](item) : openCodeEditor(item.path, item.extension);
const path = item.isSymlink ? item.linkPath : item.path;
return actionMap[fileType] ? actionMap[fileType](item) : openCodeEditor(path, item.extension);
};
const openPreview = (item: File.File, fileType: string) => {
filePreview.path = item.path;
filePreview.path = item.isSymlink ? item.linkPath : item.path;
filePreview.name = item.name;
filePreview.extension = item.extension;
filePreview.fileType = fileType;
Expand Down

0 comments on commit a53fff2

Please sign in to comment.