* Created new npm module: temptmp: This replaces node-temp usage & solves global temp file cleanup issue with concept of temp "sessions"
This commit is contained in:
parent
e10d085cab
commit
9525afddd3
|
@ -9,6 +9,7 @@ const FileEntry = require('./file_entry.js');
|
||||||
const FileDb = require('./database.js').dbs.file;
|
const FileDb = require('./database.js').dbs.file;
|
||||||
const ArchiveUtil = require('./archive_util.js');
|
const ArchiveUtil = require('./archive_util.js');
|
||||||
const CRC32 = require('./crc.js').CRC32;
|
const CRC32 = require('./crc.js').CRC32;
|
||||||
|
const Log = require('./logger.js').log;
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
@ -16,7 +17,7 @@ const async = require('async');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const paths = require('path');
|
const paths = require('path');
|
||||||
const temp = require('temp').track(); // track() cleans up temp dir/files for us
|
const temptmp = require('temptmp').createTrackedSession('file_area');
|
||||||
const iconv = require('iconv-lite');
|
const iconv = require('iconv-lite');
|
||||||
|
|
||||||
exports.isInternalArea = isInternalArea;
|
exports.isInternalArea = isInternalArea;
|
||||||
|
@ -298,7 +299,7 @@ function populateFileEntryWithArchive(fileEntry, filePath, stepInfo, iterator, c
|
||||||
return callback(null, [] );
|
return callback(null, [] );
|
||||||
}
|
}
|
||||||
|
|
||||||
temp.mkdir('enigextract-', (err, tempDir) => {
|
temptmp.mkdir( { prefix : 'enigextract-' }, (err, tempDir) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
@ -338,14 +339,11 @@ function populateFileEntryWithArchive(fileEntry, filePath, stepInfo, iterator, c
|
||||||
return next(null);
|
return next(null);
|
||||||
});
|
});
|
||||||
}, () => {
|
}, () => {
|
||||||
// cleanup, but don't wait...
|
// cleanup but don't wait
|
||||||
/*
|
temptmp.cleanup( paths => {
|
||||||
:TODO: fix global temp cleanup issue!!!
|
// note: don't use client logger here - may not be avail
|
||||||
|
Log.debug( { paths : paths, sessionId : temptmp.sessionId }, 'Cleaned up temporary files' );
|
||||||
temp.cleanup( err => {
|
});
|
||||||
// :TODO: Log me!
|
|
||||||
});*/
|
|
||||||
|
|
||||||
return callback(null);
|
return callback(null);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -18,7 +18,7 @@ const paths = require('path');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const later = require('later');
|
const later = require('later');
|
||||||
const temp = require('temp').track(); // track() cleans up temp dir/files for us
|
const temptmp = require('temptmp').createTrackedSession('ftn_bso');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const gaze = require('gaze');
|
const gaze = require('gaze');
|
||||||
const fse = require('fs-extra');
|
const fse = require('fs-extra');
|
||||||
|
@ -1153,14 +1153,14 @@ function FTNMessageScanTossModule() {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.createTempDirectories = function(cb) {
|
this.createTempDirectories = function(cb) {
|
||||||
temp.mkdir('enigftnexport-', (err, tempDir) => {
|
temptmp.mkdir( { prefix : 'enigftnexport-' }, (err, tempDir) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.exportTempDir = tempDir;
|
self.exportTempDir = tempDir;
|
||||||
|
|
||||||
temp.mkdir('enigftnimport-', (err, tempDir) => {
|
temptmp.mkdir( { prefix : 'enigftnimport-' }, (err, tempDir) => {
|
||||||
self.importTempDir = tempDir;
|
self.importTempDir = tempDir;
|
||||||
|
|
||||||
cb(err);
|
cb(err);
|
||||||
|
@ -1290,21 +1290,18 @@ FTNMessageScanTossModule.prototype.shutdown = function(cb) {
|
||||||
//
|
//
|
||||||
// Clean up temp dir/files we created
|
// Clean up temp dir/files we created
|
||||||
//
|
//
|
||||||
/*
|
temptmp.cleanup( paths => {
|
||||||
:TODO: fix global temp cleanup issue!!!
|
const fullStats = {
|
||||||
|
exportDir : this.exportTempDir,
|
||||||
temp.cleanup((err, stats) => {
|
importTemp : this.importTempDir,
|
||||||
const fullStats = Object.assign(stats, { exportTemp : this.exportTempDir, importTemp : this.importTempDir } );
|
paths : paths,
|
||||||
|
sessionId : temptmp.sessionId,
|
||||||
|
};
|
||||||
|
|
||||||
if(err) {
|
Log.trace(fullStats, 'Temporary directories cleaned up');
|
||||||
Log.warn(fullStats, 'Failed cleaning up temporary directories!');
|
|
||||||
} else {
|
|
||||||
Log.trace(fullStats, 'Temporary directories cleaned up');
|
|
||||||
}
|
|
||||||
|
|
||||||
FTNMessageScanTossModule.super_.prototype.shutdown.call(this, cb);
|
FTNMessageScanTossModule.super_.prototype.shutdown.call(this, cb);
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
FTNMessageScanTossModule.super_.prototype.shutdown.call(this, cb);
|
FTNMessageScanTossModule.super_.prototype.shutdown.call(this, cb);
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,12 +9,13 @@ const Errors = require('./enig_error.js').Errors;
|
||||||
const DownloadQueue = require('./download_queue.js');
|
const DownloadQueue = require('./download_queue.js');
|
||||||
const StatLog = require('./stat_log.js');
|
const StatLog = require('./stat_log.js');
|
||||||
const FileEntry = require('./file_entry.js');
|
const FileEntry = require('./file_entry.js');
|
||||||
|
const Log = require('./logger.js').log;
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const pty = require('ptyw.js');
|
const pty = require('ptyw.js');
|
||||||
const temp = require('temp').track(); // track() cleans up temp dir/files for us
|
const temptmp = require('temptmp').createTrackedSession('transfer_file');
|
||||||
const paths = require('path');
|
const paths = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const fse = require('fs-extra');
|
const fse = require('fs-extra');
|
||||||
|
@ -264,7 +265,7 @@ exports.getModule = class TransferFileModule extends MenuModule {
|
||||||
return callback(null, null);
|
return callback(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
temp.open( { prefix : TEMP_SUFFIX, suffix : '.txt' }, (err, tempFileInfo) => {
|
temptmp.open( { prefix : TEMP_SUFFIX, suffix : '.txt' }, (err, tempFileInfo) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err); // failed to create it
|
return callback(err); // failed to create it
|
||||||
}
|
}
|
||||||
|
@ -511,15 +512,11 @@ exports.getModule = class TransferFileModule extends MenuModule {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function cleanupTempFiles(callback) {
|
function cleanupTempFiles(callback) {
|
||||||
/* :TODO: figure out the global temp cleanup() issue!!@!
|
temptmp.cleanup( paths => {
|
||||||
temp.cleanup( err => {
|
Log.debug( { paths : paths, sessionId : temptmp.sessionId }, 'Temporary files cleaned up' );
|
||||||
if(err) {
|
|
||||||
self.client.log.warn( { error : err.message }, 'Failed to clean up temporary file/directory(s)' );
|
|
||||||
}
|
|
||||||
return callback(null); // ignore err
|
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
return callback(null);
|
return callback(null);
|
||||||
},
|
},
|
||||||
function updateUserAndSystemStats(callback) {
|
function updateUserAndSystemStats(callback) {
|
||||||
|
|
|
@ -10,11 +10,12 @@ const scanFile = require('../core/file_area.js').scanFile;
|
||||||
const ansiGoto = require('../core/ansi_term.js').goto;
|
const ansiGoto = require('../core/ansi_term.js').goto;
|
||||||
const moveFileWithCollisionHandling = require('../core/file_util.js').moveFileWithCollisionHandling;
|
const moveFileWithCollisionHandling = require('../core/file_util.js').moveFileWithCollisionHandling;
|
||||||
const pathWithTerminatingSeparator = require('../core/file_util.js').pathWithTerminatingSeparator;
|
const pathWithTerminatingSeparator = require('../core/file_util.js').pathWithTerminatingSeparator;
|
||||||
|
const Log = require('../core/logger.js').log;
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const temp = require('temp').track(); // track() cleans up temp dir/files for us
|
const temptmp = require('temptmp').createTrackedSession('upload');
|
||||||
const paths = require('path');
|
const paths = require('path');
|
||||||
|
|
||||||
exports.moduleInfo = {
|
exports.moduleInfo = {
|
||||||
|
@ -142,15 +143,16 @@ exports.getModule = class UploadModule extends MenuModule {
|
||||||
leave() {
|
leave() {
|
||||||
// remove any temp files - only do this when
|
// remove any temp files - only do this when
|
||||||
if(this.isFileTransferComplete()) {
|
if(this.isFileTransferComplete()) {
|
||||||
// :TODO: fix global temp cleanup issue!!!
|
temptmp.cleanup( paths => {
|
||||||
//temp.cleanup(); // remove any temp files
|
Log.debug( { paths : paths, sessionId : temptmp.sessionId }, 'Temporary files cleaned up' );
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
super.leave();
|
super.leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
performBlindUpload(cb) {
|
performBlindUpload(cb) {
|
||||||
temp.mkdir('enigul-', (err, tempRecvDirectory) => {
|
temptmp.mkdir( { prefix : 'enigul-' }, (err, tempRecvDirectory) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
"ptyw.js": "NuSkooler/ptyw.js",
|
"ptyw.js": "NuSkooler/ptyw.js",
|
||||||
"sqlite3": "^3.1.1",
|
"sqlite3": "^3.1.1",
|
||||||
"ssh2": "^0.5.1",
|
"ssh2": "^0.5.1",
|
||||||
"temp": "^0.8.3"
|
"temptmp" : "^1.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"lodash-migrate": "^0.3.16"
|
"lodash-migrate": "^0.3.16"
|
||||||
|
|
Loading…
Reference in New Issue