Skip to content

Commit e89722b

Browse files
committed
Fix crash when selecting a broken symlink and init extract
1 parent 9321990 commit e89722b

11 files changed

+202
-149
lines changed

Diff for: changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file. Dates are d
1414
#### Bug fix
1515

1616
- Fix processes bar cursor index display error [`f6eb9d8`](https://github.com/MHNightCat/superfile/commit/f6eb9d879f9f7ef31859e3f84c8792e2f0fc543a)
17+
- Fix [Crash when selecting a broken symlink](https://github.com/MHNightCat/superfile/issues/9) [``]()
1718

1819
# [**v1.0.0**](https://github.com/MHNightCat/superfile/releases/tag/v1.0.0)
1920

Diff for: src/components/function.go

+4
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ func ReturnMetaData(m model) model {
363363
filePath := panel.element[panel.cursor].location
364364

365365
fileInfo, err := os.Stat(filePath)
366+
if os.IsNotExist(err) {
367+
m.fileMetaData.metaData = append(m.fileMetaData.metaData, [2]string{"Link file is broken!(you cant only delete this file)", ""})
368+
return m
369+
}
366370
if err != nil {
367371
OutPutLog("Return meta data function get file state error", err)
368372
}

Diff for: src/components/globalController.go

+7
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,13 @@ func PasteItem(m model) model {
349349
return m
350350
}
351351

352+
func ExtractFile(m model) model {
353+
panel := m.fileModel.filePanels[m.filePanelFocusIndex]
354+
355+
m.fileModel.filePanels[m.filePanelFocusIndex] = panel
356+
return m
357+
}
358+
352359
func PanelCreateNewFile(m model) model {
353360
panel := m.fileModel.filePanels[m.filePanelFocusIndex]
354361
ti := textinput.New()

Diff for: src/components/icon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,5 +425,5 @@ var folders = map[string]iconStyle{
425425
"hidden": {icon: "\uf023", color: "#75715e"}, // Hidden folder - Dark yellowish
426426
"node_modules": {icon: "\ue5fa", color: "#cb3837"}, // Node modules folder - Red
427427

428-
".superfile": {icon: "󰚝", color: "#FF6F00"},
428+
"superfile": {icon: "󰚝", color: "#FF6F00"},
429429
}

Diff for: src/components/model.go

+5
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,17 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
206206
go func() {
207207
m = PasteItem(m)
208208
}()
209+
case Config.Extract[0], Config.Extract[1]:
210+
go func() {
211+
m = ExtractFile(m)
212+
}()
209213
case Config.FilePanelFileCreate[0], Config.FilePanelFileCreate[1]:
210214
m = PanelCreateNewFile(m)
211215
case Config.FilePanelFolderCreate[0], Config.FilePanelFolderCreate[1]:
212216
m = PanelCreateNewFolder(m)
213217
case Config.PinnedFolder[0], Config.PinnedFolder[1]:
214218
m = PinnedFolder(m)
219+
215220
default:
216221
// check if it's the select mode
217222
if m.fileModel.filePanels[m.filePanelFocusIndex].focusType == focus && m.fileModel.filePanels[m.filePanelFocusIndex].panelMode == selectMode {

Diff for: src/components/normalModeController.go

+25-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func DeleteSingleItem(m model) model {
8181
if err != nil {
8282
OutPutLog("Delete single item function move file to trash can error", err)
8383
}
84-
84+
8585
if err != nil {
8686
p := m.processBarModel.process[id]
8787
p.state = failure
@@ -115,6 +115,10 @@ func CopySingleItem(m model) model {
115115
}
116116
m.copyItems.items = append(m.copyItems.items, panel.element[panel.cursor].location)
117117
fileInfo, err := os.Stat(panel.element[panel.cursor].location)
118+
if os.IsNotExist(err) {
119+
m.copyItems.items = m.copyItems.items[:0]
120+
return m
121+
}
118122
if err != nil {
119123
OutPutLog("Copy single item get file state error", panel.element[panel.cursor].location, err)
120124
}
@@ -136,15 +140,31 @@ func CopySingleItem(m model) model {
136140

137141
func CutSingleItem(m model) model {
138142
panel := m.fileModel.filePanels[m.filePanelFocusIndex]
143+
m.copyItems.cut = true
139144
m.copyItems.items = m.copyItems.items[:0]
140145
if len(panel.element) == 0 {
141146
return m
142147
}
143148
m.copyItems.items = append(m.copyItems.items, panel.element[panel.cursor].location)
144-
m.copyItems.cut = true
145-
m.copyItems.originalPanel = originalPanel{
146-
index: m.filePanelFocusIndex,
147-
location: panel.location,
149+
fileInfo, err := os.Stat(panel.element[panel.cursor].location)
150+
if os.IsNotExist(err) {
151+
m.copyItems.items = m.copyItems.items[:0]
152+
return m
153+
}
154+
if err != nil {
155+
OutPutLog("Cut single item get file state error", panel.element[panel.cursor].location, err)
156+
}
157+
158+
if !fileInfo.IsDir() && float64(fileInfo.Size())/(1024*1024) < 250 {
159+
fileContent, err := os.ReadFile(panel.element[panel.cursor].location)
160+
161+
if err != nil {
162+
OutPutLog("Cut single item read file error", panel.element[panel.cursor].location, err)
163+
}
164+
165+
if err := clipboard.WriteAll(string(fileContent)); err != nil {
166+
OutPutLog("Cut single item write file error", panel.element[panel.cursor].location, err)
167+
}
148168
}
149169
m.fileModel.filePanels[m.filePanelFocusIndex] = panel
150170
return m

Diff for: src/components/selectModeController.go

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package components
22

33
import (
4-
"os"
5-
"path/filepath"
64
"github.com/atotto/clipboard"
75
"github.com/charmbracelet/bubbles/progress"
86
"github.com/lithammer/shortuuid"
97
"github.com/rkoesters/xdg/trash"
8+
"os"
9+
"path/filepath"
1010
)
1111

1212
func SingleItemSelect(m model) model {
@@ -146,6 +146,9 @@ func CopyMultipleItem(m model) model {
146146
}
147147
m.copyItems.items = panel.selected
148148
fileInfo, err := os.Stat(panel.selected[0])
149+
if os.IsNotExist(err) {
150+
return m
151+
}
149152
if err != nil {
150153
OutPutLog("Copy multiple item function get file state error", panel.selected[0], err)
151154
}
@@ -167,15 +170,30 @@ func CopyMultipleItem(m model) model {
167170

168171
func CutMultipleItem(m model) model {
169172
panel := m.fileModel.filePanels[m.filePanelFocusIndex]
173+
m.copyItems.cut = true
170174
m.copyItems.items = m.copyItems.items[:0]
171175
if len(panel.selected) == 0 {
172176
return m
173177
}
174178
m.copyItems.items = panel.selected
175-
m.copyItems.cut = true
176-
m.copyItems.originalPanel = originalPanel{
177-
index: m.filePanelFocusIndex,
178-
location: panel.location,
179+
fileInfo, err := os.Stat(panel.selected[0])
180+
if os.IsNotExist(err) {
181+
return m
182+
}
183+
if err != nil {
184+
OutPutLog("Copy multiple item function get file state error", panel.selected[0], err)
185+
}
186+
187+
if !fileInfo.IsDir() && float64(fileInfo.Size())/(1024*1024) < 250 {
188+
fileContent, err := os.ReadFile(panel.selected[0])
189+
190+
if err != nil {
191+
OutPutLog("Copy multiple item function read file error", err)
192+
}
193+
194+
if err := clipboard.WriteAll(string(fileContent)); err != nil {
195+
OutPutLog("Copy multiple item function write file to clipboard error", err)
196+
}
179197
}
180198
m.fileModel.filePanels[m.filePanelFocusIndex] = panel
181199
return m

Diff for: src/components/type.go

+11-13
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ type sideBarModel struct {
147147

148148
// Model for pinned items in sidebar
149149
type pinnedModel struct {
150-
folder []folder
150+
folder []folder
151151
}
152152

153153
// Folder within pinned items
@@ -232,32 +232,31 @@ type ThemeType struct {
232232
// Configuration settings
233233
type ConfigType struct {
234234
Theme string
235-
236-
// HotKey setting
235+
237236
Reload [2]string
237+
Quit [2]string
238238

239-
Quit [2]string
240239
ListUp [2]string
241240
ListDown [2]string
242241

243-
NextFilePanel [2]string
244-
PreviousFilePanel [2]string
242+
PinnedFolder [2]string
243+
245244
CloseFilePanel [2]string
246245
CreateNewFilePanel [2]string
247246

248-
ChangePanelMode [2]string
249-
250-
FocusOnSideBar [2]string
247+
NextFilePanel [2]string
248+
PreviousFilePanel [2]string
251249
FocusOnProcessBar [2]string
250+
FocusOnSideBar [2]string
252251
FocusOnMetaData [2]string
253252

254-
PasteItem [2]string
253+
ChangePanelMode [2]string
255254

256255
FilePanelFolderCreate [2]string
257256
FilePanelFileCreate [2]string
258257
FilePanelItemRename [2]string
259-
260-
PinnedFolder [2]string
258+
PasteItem [2]string
259+
Extract [2]string
261260

262261
Cancel [2]string
263262
Confirm [2]string
@@ -273,7 +272,6 @@ type ConfigType struct {
273272
FilePanelSelectModeItemSelectUp [2]string
274273
FilePanelSelectModeItemDelete [2]string
275274
FilePanelSelectModeItemCopy [2]string
276-
FilePanelSelectModeItemPast [2]string
277275
FilePanelSelectModeItemCut [2]string
278276
FilePanelSelectAllItem [2]string
279277
}

Diff for: src/superfile/config/config.json

+52-51
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,53 @@
11
{
2-
"theme": "gruvbox",
3-
4-
"_COMMIT_HOTKEY": "",
5-
6-
"_COMMIT_global_hotkey": "Here is global, all global key cant conflicts with other hotkeys",
7-
"reload": ["ctrl+r", ""],
8-
"quit": ["esc", "q"],
9-
10-
"listUp": ["up", "k"],
11-
"listDown": ["down", "j"],
12-
13-
"pinnedFolder": ["ctrl+p", ""],
14-
15-
"closeFilePanel": ["ctrl+w", ""],
16-
"createNewFilePanel": ["ctrl+n", ""],
17-
18-
"nextFilePanel": ["tab", ""],
19-
"previousFilePanel": ["shift+left", ""],
20-
"focusOnProcessBar": ["p", ""],
21-
"focusOnSideBar": ["b", ""],
22-
"focusOnMetaData": ["m", ""],
23-
24-
"changePanelMode": ["v", ""],
25-
26-
"filePanelFolderCreate": ["f", ""],
27-
"filePanelFileCreate": ["c", ""],
28-
"filePanelItemRename": ["r", ""],
29-
"pasteItem": ["ctrl+v", ""],
30-
31-
"_COMMIT_special_hotkey": "These hotkeys do not conflict with any other keys (including global hotkey)",
32-
"cancel": ["ctrl+c", "esc"],
33-
"confirm": ["enter", ""],
34-
35-
"_COMMIT_normal_mode_hotkey": "Here is normal mode hotkey you can conflicts with other mode (cant conflicts with global hotkey)",
36-
"deleteItem": ["ctrl+d", ""],
37-
"selectItem": ["enter", "l"],
38-
"parentFolder": ["h", "backspace"],
39-
"copySingleItem": ["ctrl+c", ""],
40-
"cutSingleItem": ["ctrl+x", ""],
41-
42-
"_COMMIT_select_mode_hotkey": "Here is select mode hotkey you can conflicts with other mode (cant conflicts with global hotkey)",
43-
"filePanelSelectModeItemSingleSelect": ["enter", "l"],
44-
"filePanelSelectModeItemSelectDown": ["shift+down", "J"],
45-
"filePanelSelectModeItemSelectUp": ["shift+up", "K"],
46-
"filePanelSelectModeItemDelete": ["ctrl+d", "delete"],
47-
"filePanelSelectModeItemCopy": ["ctrl+c", ""],
48-
"filePanelSelectModeItemCut": ["ctrl+x", ""],
49-
"filePanelSelectAllItem": ["ctrl+a", ""],
50-
51-
"_COMMIT_process_bar_hotkey": "Here is process bar panel hotkey you can conflicts with other mode (cant conflicts global hotkey)"
52-
}
2+
"theme": "gruvbox",
3+
4+
"_COMMIT_HOTKEY": "",
5+
6+
"_COMMIT_global_hotkey": "Here is global, all global key cant conflicts with other hotkeys",
7+
"reload": ["ctrl+r", ""],
8+
"quit": ["esc", "q"],
9+
10+
"listUp": ["up", "k"],
11+
"listDown": ["down", "j"],
12+
13+
"pinnedFolder": ["ctrl+p", ""],
14+
15+
"closeFilePanel": ["ctrl+w", ""],
16+
"createNewFilePanel": ["ctrl+n", ""],
17+
18+
"nextFilePanel": ["tab", ""],
19+
"previousFilePanel": ["shift+left", ""],
20+
"focusOnProcessBar": ["p", ""],
21+
"focusOnSideBar": ["b", ""],
22+
"focusOnMetaData": ["m", ""],
23+
24+
"changePanelMode": ["v", ""],
25+
26+
"filePanelFolderCreate": ["f", ""],
27+
"filePanelFileCreate": ["c", ""],
28+
"filePanelItemRename": ["r", ""],
29+
"pasteItem": ["ctrl+v", ""],
30+
"extract": ["ctrl+u", ""],
31+
32+
"_COMMIT_special_hotkey": "These hotkeys do not conflict with any other keys (including global hotkey)",
33+
"cancel": ["ctrl+c", "esc"],
34+
"confirm": ["enter", ""],
35+
36+
"_COMMIT_normal_mode_hotkey": "Here is normal mode hotkey you can conflicts with other mode (cant conflicts with global hotkey)",
37+
"deleteItem": ["ctrl+d", ""],
38+
"selectItem": ["enter", "l"],
39+
"parentFolder": ["h", "backspace"],
40+
"copySingleItem": ["ctrl+c", ""],
41+
"cutSingleItem": ["ctrl+x", ""],
42+
43+
"_COMMIT_select_mode_hotkey": "Here is select mode hotkey you can conflicts with other mode (cant conflicts with global hotkey)",
44+
"filePanelSelectModeItemSingleSelect": ["enter", "l"],
45+
"filePanelSelectModeItemSelectDown": ["shift+down", "J"],
46+
"filePanelSelectModeItemSelectUp": ["shift+up", "K"],
47+
"filePanelSelectModeItemDelete": ["ctrl+d", "delete"],
48+
"filePanelSelectModeItemCopy": ["ctrl+c", ""],
49+
"filePanelSelectModeItemCut": ["ctrl+x", ""],
50+
"filePanelSelectAllItem": ["ctrl+a", ""],
51+
52+
"_COMMIT_process_bar_hotkey": "Here is process bar panel hotkey you can conflicts with other mode (cant conflicts global hotkey)"
53+
}

0 commit comments

Comments
 (0)