-
Notifications
You must be signed in to change notification settings - Fork 2
/
entry.go
83 lines (75 loc) · 1.71 KB
/
entry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package cwl
import (
"os"
"path/filepath"
)
// Entry represents fs entry, it means [File|Directory|Dirent]
type Entry struct {
Class string
Location string
Path string
Basename string
File
Directory
Dirent
}
// File represents file entry.
// @see http://www.commonwl.org/v1.0/CommandLineTool.html#File
type File struct {
Dirname string
Size int64
Format string
}
// Directory represents direcotry entry.
// @see http://www.commonwl.org/v1.0/CommandLineTool.html#Directory
type Directory struct {
Listing []Entry
}
// Dirent represents ?
// @see http://www.commonwl.org/v1.0/CommandLineTool.html#Dirent
type Dirent struct {
Entry string
EntryName string
Writable bool
}
// NewList constructs a list of Entry from interface
func (_ Entry) NewList(i interface{}) []Entry {
dest := []Entry{}
switch x := i.(type) {
case string:
dest = append(dest, Entry{}.New(x))
case []interface{}:
for _, v := range x {
dest = append(dest, Entry{}.New(v))
}
}
return dest
}
// New constructs an Entry from interface
func (_ Entry) New(i interface{}) Entry {
dest := Entry{}
switch x := i.(type) {
case string:
dest.Location = x
case map[string]interface{}:
for key, v := range x {
switch key {
case "entryname":
dest.EntryName = v.(string)
case "entry":
dest.Entry = v.(string)
case "writable":
dest.Writable = v.(bool)
}
}
}
return dest
}
// LinkTo creates hardlink of this entry under destdir.
func (entry *Entry) LinkTo(destdir, srcdir string) error {
destpath := filepath.Join(destdir, filepath.Base(entry.Location))
if filepath.IsAbs(entry.Location) {
return os.Link(entry.Location, destpath)
}
return os.Link(filepath.Join(srcdir, entry.Location), destpath)
}