Skip to content

Commit 9cc43eb

Browse files
committed
Use stat() instead of access(). Remove support for node<=0.12
1 parent f2426ab commit 9cc43eb

File tree

5 files changed

+75
-55
lines changed

5 files changed

+75
-55
lines changed

.travis.yml

-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
language: node_js
22
node_js:
3-
- "0.8"
4-
- "0.10"
53
- "0.12"
64
- "iojs-1"
75
- "iojs-2"
8-
os:
9-
- linux
10-
- osx
116
notifications:
127
email:
138

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Detects if `resolv.conf` is created, deleted, appended, modified or renamed.
1212
Node Compatibility
1313
---------------------
1414

15-
Supports Node.js v0.8.0+ and io.js v1.0.0+
15+
Supports Node.js v0.12.0+ and io.js v1.0.0+
1616

1717
Please let me know if you have problems running it on a later version of Node or
1818
have platform-specific problems.

lib/resolvmon.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ function watchFile(filepath, callback) {
1414
fdir = path.dirname(fpath),
1515
fname = path.basename(fpath);
1616

17-
fs.accessSync(fdir, fs.F_OK);
17+
fs.statSync(fdir);
1818

1919
return fs.watch(fdir, {persistent: false, recursive: false}, function (event, changed_fname) {
2020

2121
if (changed_fname === fname) {
2222

23-
fs.access(fpath, fs.F_OK, function (err) {
23+
fs.stat(fpath, function (err, stats) {
2424
callback && callback(null, !err, fpath);
2525
});
2626

@@ -109,7 +109,7 @@ ResolvMon.prototype.update = function (callback) {
109109
fdir = path.dirname(fpath);
110110

111111
try {
112-
fs.accessSync(fdir, fs.F_OK);
112+
fs.statSync(fdir);
113113
} catch (ex) {
114114
self._emit('error', ex);
115115
if (callback) callback(ex, []); else throw ex;

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
],
2121
"main": "lib/resolvmon.js",
2222
"engines": {
23-
"node": ">= 0.8"
23+
"node": ">= 0.12"
2424
},
2525
"dependencies": {},
2626
"devDependencies": {
27-
"mocha": "^2.2.4",
28-
"chai": "^2.3.0",
29-
"temp": "^0.8.1"
27+
"mocha": "~2.2.4",
28+
"chai": "~2.3.0",
29+
"temp": "~0.8.1"
3030
},
3131
"scripts": {
3232
"test": "./node_modules/mocha/bin/mocha test"

test/06_watch.js

+67-42
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,36 @@ describe('resolvmon watch', function () {
8080
it('detect resolv.conf delete', function (done) {
8181

8282
resolvmon.setPath(temporary_conf);
83-
fs.writeFileSync(temporary_conf, "nameserver 127.0.0.11\nnameserver 127.0.0.22\n");
8483

85-
resolvmon.on('error', function (err) {
84+
fs.writeFile(temporary_conf, "nameserver 127.0.0.11\nnameserver 127.0.0.22\n", function (err) {
85+
8686
expect(err).not.to.be.defined;
87-
done(err);
88-
});
8987

90-
resolvmon.on('update', function (nameservers) {
88+
if (err) {
89+
return done();
90+
}
9191

92-
expect(nameservers).to.be.defined;
93-
expect(nameservers).to.be.instanceof(Array);
94-
expect(nameservers).to.eql([]);
92+
resolvmon.on('error', function (err) {
93+
expect(err).not.to.be.defined;
94+
done(err);
95+
});
9596

96-
done();
97+
resolvmon.on('update', function (nameservers) {
9798

98-
});
99+
expect(nameservers).to.be.defined;
100+
expect(nameservers).to.be.instanceof(Array);
101+
expect(nameservers).to.eql([]);
99102

100-
resolvmon.start();
103+
done();
104+
105+
});
106+
107+
resolvmon.start();
108+
109+
process.nextTick(function () {
110+
fs.unlinkSync(temporary_conf);
111+
});
101112

102-
process.nextTick(function () {
103-
fs.unlink(temporary_conf);
104113
});
105114

106115
});
@@ -109,55 +118,71 @@ describe('resolvmon watch', function () {
109118

110119
resolvmon.setPath(temporary_conf);
111120

112-
fs.writeFileSync(temporary_conf, "nameserver 127.0.0.12\nnameserver 127.0.0.23");
121+
fs.writeFile(temporary_conf, "nameserver 127.0.0.12\nnameserver 127.0.0.23", function (err) {
113122

114-
resolvmon.on('error', function (err) {
115123
expect(err).not.to.be.defined;
116-
done(err);
117-
});
118124

119-
resolvmon.on('update', function (nameservers) {
125+
if (err) {
126+
return done();
127+
}
120128

121-
expect(nameservers).to.be.defined;
122-
expect(nameservers).to.be.instanceof(Array);
123-
expect(nameservers).to.eql(['127.0.0.12', '127.0.0.23', '127.0.0.34', '127.0.0.45']);
129+
resolvmon.on('error', function (err) {
130+
expect(err).not.to.be.defined;
131+
done(err);
132+
});
124133

125-
done();
134+
resolvmon.on('update', function (nameservers) {
126135

127-
});
136+
expect(nameservers).to.be.defined;
137+
expect(nameservers).to.be.instanceof(Array);
138+
expect(nameservers).to.eql(['127.0.0.12', '127.0.0.23', '127.0.0.34', '127.0.0.45']);
128139

129-
resolvmon.start();
140+
done();
130141

131-
process.nextTick(function () {
132-
fs.appendFileSync(temporary_conf, "\nnameserver 127.0.0.34\nnameserver 127.0.0.45\n");
133-
});
142+
});
143+
144+
resolvmon.start();
134145

146+
process.nextTick(function () {
147+
fs.appendFileSync(temporary_conf, "\nnameserver 127.0.0.34\nnameserver 127.0.0.45\n");
148+
});
149+
150+
151+
});
135152

136153
});
137154

138155
it('detect resolv.conf modification', function (done) {
139156

140157
resolvmon.setPath(temporary_conf);
141158

142-
fs.writeFileSync(temporary_conf, "nameserver 127.0.0.77\nnameserver 127.0.0.88\n");
159+
fs.writeFile(temporary_conf, "nameserver 127.0.0.77\nnameserver 127.0.0.88\n", function (err) {
143160

144-
resolvmon.on('error', function (err) {
145161
expect(err).not.to.be.defined;
146-
done(err);
147-
});
148162

149-
resolvmon.on('update', function (nameservers) {
163+
if (err) {
164+
return done();
165+
}
150166

151-
expect(nameservers).to.be.defined;
152-
expect(nameservers).to.be.instanceof(Array);
153-
expect(nameservers).to.eql(['127.0.0.100', '127.0.0.200']);
154-
done();
155-
});
167+
resolvmon.on('error', function (err) {
168+
expect(err).not.to.be.defined;
169+
done(err);
170+
});
156171

157-
resolvmon.start();
172+
resolvmon.on('update', function (nameservers) {
173+
174+
expect(nameservers).to.be.defined;
175+
expect(nameservers).to.be.instanceof(Array);
176+
expect(nameservers).to.eql(['127.0.0.100', '127.0.0.200']);
177+
done();
178+
});
179+
180+
resolvmon.start();
181+
182+
process.nextTick(function () {
183+
fs.writeFileSync(temporary_conf, "nameserver 127.0.0.100\nnameserver 127.0.0.200");
184+
});
158185

159-
process.nextTick(function () {
160-
fs.writeFileSync(temporary_conf, "nameserver 127.0.0.100\nnameserver 127.0.0.200");
161186
});
162187

163188
});
@@ -190,7 +215,7 @@ describe('resolvmon watch', function () {
190215
after(function () {
191216

192217
try {
193-
fs.unlink(temporary_conf + '.renamed');
218+
fs.unlinkSync(temporary_conf + '.renamed');
194219
} catch (ex) {
195220
}
196221

@@ -226,7 +251,7 @@ describe('resolvmon watch', function () {
226251
after(function () {
227252

228253
try {
229-
fs.unlink(temporary_conf + '.renamed');
254+
fs.unlinkSync(temporary_conf + '.renamed');
230255
} catch (ex) {
231256
}
232257

0 commit comments

Comments
 (0)