1 | var path = require('path');
|
2 |
|
3 | var counter = 0;
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | function Item() {
|
12 |
|
13 | var now = Date.now();
|
14 |
|
15 | |
16 |
|
17 |
|
18 |
|
19 | this._atime = new Date(now);
|
20 |
|
21 | |
22 |
|
23 |
|
24 |
|
25 | this._ctime = new Date(now);
|
26 |
|
27 | |
28 |
|
29 |
|
30 |
|
31 | this._mtime = new Date(now);
|
32 |
|
33 | |
34 |
|
35 |
|
36 | this._mode = 0666;
|
37 |
|
38 | |
39 |
|
40 |
|
41 |
|
42 | this._uid = process.getuid ? process.getuid() : undefined;
|
43 |
|
44 | |
45 |
|
46 |
|
47 |
|
48 | this._gid = process.getgid ? process.getgid() : undefined;
|
49 |
|
50 | |
51 |
|
52 |
|
53 |
|
54 | this._id = ++counter;
|
55 |
|
56 | |
57 |
|
58 |
|
59 | this.links = 0;
|
60 |
|
61 | }
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | Item.prototype.getATime = function() {
|
69 | return this._atime;
|
70 | };
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | Item.prototype.setATime = function(atime) {
|
78 | this._atime = atime;
|
79 | };
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | Item.prototype.getCTime = function() {
|
87 | return this._ctime;
|
88 | };
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | Item.prototype.setCTime = function(ctime) {
|
96 | this._ctime = ctime;
|
97 | };
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | Item.prototype.getMTime = function() {
|
105 | return this._mtime;
|
106 | };
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | Item.prototype.setMTime = function(mtime) {
|
114 | this._mtime = mtime;
|
115 | };
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | Item.prototype.getMode = function() {
|
123 | return this._mode;
|
124 | };
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | Item.prototype.setMode = function(mode) {
|
132 | this.setCTime(new Date());
|
133 | this._mode = mode;
|
134 | };
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | Item.prototype.getUid = function() {
|
142 | return this._uid;
|
143 | };
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | Item.prototype.setUid = function(uid) {
|
151 | this.setCTime(new Date());
|
152 | this._uid = uid;
|
153 | };
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 | Item.prototype.getGid = function() {
|
161 | return this._gid;
|
162 | };
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 | Item.prototype.setGid = function(gid) {
|
170 | this.setCTime(new Date());
|
171 | this._gid = gid;
|
172 | };
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 | Item.prototype.getStats = function() {
|
180 | return {
|
181 | dev: 8675309,
|
182 | nlink: this.links,
|
183 | uid: this.getUid(),
|
184 | gid: this.getGid(),
|
185 | rdev: 0,
|
186 | blksize: 4096,
|
187 | ino: this._id,
|
188 | atime: this.getATime(),
|
189 | mtime: this.getMTime(),
|
190 | ctime: this.getCTime(),
|
191 | };
|
192 | };
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 | Item.prototype.toString = function() {
|
200 | return '[' + this.constructor.name + ']';
|
201 | };
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 | exports = module.exports = Item;
|