Permalink
Browse files

Use the node-temp library instead of hardcoding /tmp/

  • Loading branch information...
1 parent e235dbf commit 6ea272bf7c05740939e2e9e338e3a4fa917b896f @jhurliman committed Jul 31, 2012
Showing with 7 additions and 5 deletions.
  1. +5 −4 models/mysql.js
  2. +2 −1 package.json
View
@@ -5,6 +5,7 @@
var fs = require('fs');
var mysql = require('mysql');
+var temp = require('temp');
var config = require('../config');
exports.fpQuery = fpQuery;
@@ -174,18 +175,18 @@ function addTrack(trackID, artistID, fp, callback) {
if (info.affectedRows !== 1) return callback('Track insert failed');
// Write out the codes to a file for bulk insertion into MySQL
- var tempName = '/tmp/echoprint-' + trackID;
+ var tempName = temp.path({ prefix: 'echoprint-' + trackID, suffix: '.csv' });
writeCodesToFile(tempName, fp, trackID, function(err) {
if (err) return callback(err);
// Bulk insert the codes
sql = 'LOAD DATA INFILE ? IGNORE INTO TABLE codes';
client.query(sql, [tempName], function(err, info) {
// Remove the temporary file
- //fs.unlink(tempName, function(err2) {
- // if (!err) err = err2;
+ fs.unlink(tempName, function(err2) {
+ if (!err) err = err2;
callback(err);
- //});
+ });
});
});
});
View
@@ -5,6 +5,7 @@
"mysql": "0.9.5",
"winston": "0.5.9",
"jade": "0.20.3",
- "async": "0.1.16"
+ "async": "0.1.16",
+ "temp": "0.4.0"
}
}

0 comments on commit 6ea272b

Please sign in to comment.