Repository navigation
Expand file tree
/
Copy pathfile.js
More file actions
102 lines (82 loc) · 1.89 KB
/
Copy pathfile.js
File metadata and controls
102 lines (82 loc) · 1.89 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
export default class File {
static modes = {
// Non-executable, non-symlink
NORMAL: '100644',
// +x bit set
EXECUTABLE: '100755',
// Soft link to another filesystem location
SYMLINK: '120000',
// Submodule mount point
GITLINK: '160000',
}
constructor({path, mode, symlink}) {
this.path = path;
this.mode = mode;
this.symlink = symlink;
}
getPath() {
return this.path;
}
getMode() {
return this.mode;
}
getSymlink() {
return this.symlink;
}
isSymlink() {
return this.getMode() === this.constructor.modes.SYMLINK;
}
isRegularFile() {
return this.getMode() === this.constructor.modes.NORMAL || this.getMode() === this.constructor.modes.EXECUTABLE;
}
isExecutable() {
return this.getMode() === this.constructor.modes.EXECUTABLE;
}
isPresent() {
return true;
}
clone(opts = {}) {
return new File({
path: opts.path !== undefined ? opts.path : this.path,
mode: opts.mode !== undefined ? opts.mode : this.mode,
symlink: opts.symlink !== undefined ? opts.symlink : this.symlink,
});
}
}
export const nullFile = {
getPath() {
/* istanbul ignore next */
return null;
},
getMode() {
/* istanbul ignore next */
return null;
},
getSymlink() {
/* istanbul ignore next */
return null;
},
isSymlink() {
return false;
},
isRegularFile() {
return false;
},
isExecutable() {
return false;
},
isPresent() {
return false;
},
clone(opts = {}) {
if (opts.path === undefined && opts.mode === undefined && opts.symlink === undefined) {
return this;
} else {
return new File({
path: opts.path !== undefined ? opts.path : this.getPath(),
mode: opts.mode !== undefined ? opts.mode : this.getMode(),
symlink: opts.symlink !== undefined ? opts.symlink : this.getSymlink(),
});
}
},
};