MCPcopy Create free account
hub / github.com/cogentcore/core / pasteCheckExisting

Method pasteCheckExisting

filetree/copypaste.go:79–117  ·  view source on GitHub ↗

pasteCheckExisting checks for existing files in target node directory if that is non-nil (otherwise just uses absolute path), and returns list of existing and node for last one if exists.

(tfn *Node, md mimedata.Mimes, externalDrop bool)

Source from the content-addressed store, hash-verified

77// that is non-nil (otherwise just uses absolute path), and returns list of existing
78// and node for last one if exists.
79func (fn *Node) pasteCheckExisting(tfn *Node, md mimedata.Mimes, externalDrop bool) ([]string, *Node) {
80 froot := fn.FileRoot
81 tpath := ""
82 if tfn != nil {
83 tpath = string(tfn.Filepath)
84 }
85 nf := len(md)
86 if !externalDrop {
87 nf /= 3
88 }
89 var sfn *Node
90 var existing []string
91 for i := 0; i < nf; i++ {
92 var d *mimedata.Data
93 if !externalDrop {
94 d = md[i*3+1]
95 npath := string(md[i*3].Data)
96 sfni := froot.FindPath(npath)
97 if sfni != nil {
98 sfn = AsNode(sfni)
99 }
100 } else {
101 d = md[i] // just a list
102 }
103 if d.Type != fileinfo.TextPlain {
104 continue
105 }
106 path := string(d.Data)
107 path = strings.TrimPrefix(path, "file://")
108 if tfn != nil {
109 _, fnm := filepath.Split(path)
110 path = filepath.Join(tpath, fnm)
111 }
112 if errors.Log1(fsx.FileExists(path)) {
113 existing = append(existing, path)
114 }
115 }
116 return existing, sfn
117}
118
119// pasteCopyFiles copies files in given data into given target directory
120func (fn *Node) pasteCopyFiles(tdir *Node, md mimedata.Mimes, externalDrop bool) {

Callers 2

pasteCopyFilesCheckMethod · 0.95
pasteFilesMethod · 0.95

Calls 5

Log1Function · 0.92
FileExistsFunction · 0.92
FindPathMethod · 0.80
SplitMethod · 0.80
AsNodeFunction · 0.70

Tested by

no test coverage detected