Skip to content

Commit

Permalink
fix EntryNode issues
Browse files Browse the repository at this point in the history
  • Loading branch information
oligo committed Oct 21, 2024
1 parent 8c9fcf0 commit 9d2bd54
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion explorer/file_chooser.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,12 @@ func (vw *FileChooserDialog) OnNavTo(intent view.Intent) error {
}

vw.fileExplorer.bottomPanel.addFolderCb = func(folderName string) error {
return vw.fileExplorer.viewer.entryTree.AddChild(folderName, FolderNode)
err := vw.fileExplorer.viewer.entryTree.AddChild(folderName, FolderNode)
if err == nil {
vw.fileExplorer.viewer.refresh()
}

return err
}

if f, ok := intent.Params["filter"]; ok {
Expand Down
12 changes: 6 additions & 6 deletions explorer/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ func (n *EntryNode) AddChild(name string, kind NodeKind) error {
return errors.New("empty file/folder name")
}

if err := n.checkDuplicate(name); err != nil {
return err
if n.exists(name) {
return errors.New("duplicated file/folder name")
}

path := filepath.Join(n.Path, name)
Expand Down Expand Up @@ -194,11 +194,11 @@ func (n *EntryNode) AddChild(name string, kind NodeKind) error {
return nil
}

func (n *EntryNode) checkDuplicate(name string) error {
func (n *EntryNode) exists(name string) bool {
filename := filepath.Join(n.Path, name)
_, err := os.Stat(filename)

return err
return err == nil
}

// Update set a new name for the current file/folder.
Expand All @@ -211,8 +211,8 @@ func (n *EntryNode) UpdateName(newName string) error {
return nil
}

if err := n.Parent.checkDuplicate(newName); err != nil {
return err
if n.Parent.exists(newName) {
return errors.New("duplicated file/folder name")
}

newPath := filepath.Join(filepath.Dir(n.Path), newName)
Expand Down

0 comments on commit 9d2bd54

Please sign in to comment.