mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-07 13:15:28 +02:00
* Fix file descriptor leak
* Allow noWatch init (e.g. for oputil)
This commit is contained in:
parent
b6e7ecb193
commit
2cef12f47e
1 changed files with 14 additions and 6 deletions
|
@ -50,19 +50,21 @@ module.exports = class ArchiveUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
// singleton access
|
// singleton access
|
||||||
static getInstance() {
|
static getInstance(noWatch = false) {
|
||||||
if(!archiveUtil) {
|
if(!archiveUtil) {
|
||||||
archiveUtil = new ArchiveUtil();
|
archiveUtil = new ArchiveUtil();
|
||||||
archiveUtil.init();
|
archiveUtil.init(noWatch);
|
||||||
}
|
}
|
||||||
return archiveUtil;
|
return archiveUtil;
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init(noWatch = false) {
|
||||||
this.reloadConfig();
|
this.reloadConfig();
|
||||||
Events.on(Events.getSystemEvents().ConfigChanged, () => {
|
if(!noWatch) {
|
||||||
this.reloadConfig();
|
Events.on(Events.getSystemEvents().ConfigChanged, () => {
|
||||||
});
|
this.reloadConfig();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reloadConfig() {
|
reloadConfig() {
|
||||||
|
@ -147,6 +149,10 @@ module.exports = class ArchiveUtil {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
detectType(path, cb) {
|
detectType(path, cb) {
|
||||||
|
const closeFile = (fd) => {
|
||||||
|
fs.close(fd, () => { /* sadface */ });
|
||||||
|
};
|
||||||
|
|
||||||
fs.open(path, 'r', (err, fd) => {
|
fs.open(path, 'r', (err, fd) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
|
@ -155,6 +161,7 @@ module.exports = class ArchiveUtil {
|
||||||
const buf = Buffer.alloc(this.longestSignature);
|
const buf = Buffer.alloc(this.longestSignature);
|
||||||
fs.read(fd, buf, 0, buf.length, 0, (err, bytesRead) => {
|
fs.read(fd, buf, 0, buf.length, 0, (err, bytesRead) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
|
closeFile(fd);
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,6 +183,7 @@ module.exports = class ArchiveUtil {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
closeFile(fd);
|
||||||
return cb(archFormat ? null : Errors.General('Unknown type'), archFormat);
|
return cb(archFormat ? null : Errors.General('Unknown type'), archFormat);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue