This repository has been archived by the owner on Jan 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfs-anticache.js
64 lines (56 loc) · 1.59 KB
/
fs-anticache.js
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
const yargs = require('yargs');
const fs = require('fs');
const net = require('net');
const readline = require('readline');
process.on('uncaughtException', function (err) {
console.error('[E] ', err);
});
// - COMMAND -----------------
const argv = yargs
.option('port', {
alias: 'p',
description: 'Listens to port',
type: 'number',
default: 8998,
})
.option('ip', {
alias: 'i',
description: 'IP to listen',
type: 'string',
default: '0.0.0.0',
})
.option('verbose', {
alias: 'v',
description: 'Verbose mode',
type: 'boolean',
})
.strict()
.wrap(Math.min(yargs.terminalWidth(), 100))
.help()
.alias('help', 'h')
.version(false)
.argv;
// - START -----------------
const verbose = argv.verbose;
const server = net.createServer(function (socket) {
readline.createInterface({
input: socket,
output: socket,
}).on('line', function (line) {
const filePath = './' + line.trim();
try {
// Assumes opening file with write access drops NFS cache
fs.open(filePath, 'r+', (error, fileDescriptor) => {
verbose && console.info(`[` + (error ? '-' : '+') + `] ${filePath}`);
fileDescriptor && fs.close(fileDescriptor, () => {
// do nothing
});
});
} catch (e) {
verbose && console.info(`[-] ${filePath}`);
}
});
});
server.listen(argv.port, argv.ip, () => {
console.log(`Listening to ${argv.ip}:${argv.port}`);
});