Skip to content

Commit

Permalink
feat: check if symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakenelf committed Apr 6, 2024
1 parent d4c4b82 commit c853f49
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions filetree/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,30 @@ func (m Model) GetDirectoryListingCmd(directoryName string) tea.Cmd {
continue
}

filePath := filepath.Join(directoryPath, file.Name())
isDirectory := fileInfo.IsDir()

isSymlink := fileInfo.Mode()&os.ModeSymlink != 0

if isSymlink {
symlinkPath, _ := filepath.EvalSymlinks(filepath.Join(directoryPath, file.Name()))
filePath = symlinkPath
symlinkInfo, err := os.Stat(symlinkPath)
if err != nil {
return errorMsg(err.Error())
}

isDirectory = symlinkInfo.IsDir()
}

fileSize := ConvertBytesToSizeString(fileInfo.Size())

directoryItems = append(directoryItems, DirectoryItem{
Name: file.Name(),
Details: fileInfo.Mode().String(),
Path: filepath.Join(directoryPath, file.Name()),
Path: filePath,
Extension: filepath.Ext(fileInfo.Name()),
IsDirectory: fileInfo.IsDir(),
IsDirectory: isDirectory,
FileInfo: fileInfo,
FileSize: fileSize,
})
Expand Down

0 comments on commit c853f49

Please sign in to comment.