Skip to content

Commit

Permalink
Bug where the sqlite DB was closed so subsequent getCookies failed
Browse files Browse the repository at this point in the history
  • Loading branch information
bertrandom committed Jan 30, 2015
1 parent 3f958ef commit 4d74164
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
14 changes: 14 additions & 0 deletions example/double-smarf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var chrome = require('../index');

chrome.getCookies('http://smarf.toomanycooks.kitchen', function (err, cookies) {
chrome.getCookies('http://smarf.toomanycooks.kitchen', function (err, cookies) {

if (err) {
console.error(err);
return;
}

console.log(cookies);

});
});
17 changes: 13 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var sqlite3 = require('sqlite3'),
crypto = require('crypto'),
Cookie = tough.Cookie,
path,
ITERATIONS;
ITERATIONS,
dbClosed = false;

if (process.platform === 'darwin') {

Expand Down Expand Up @@ -223,6 +224,11 @@ var getCookies = function (uri, format, callback) {
return callback(new Error('Could not parse URI, format should be http://www.example.com/path/'));
}

if (dbClosed) {
db = new sqlite3.Database(path);
dbClosed = false;
}

getDerivedKey(function (err, derivedKey) {

if (err) {
Expand Down Expand Up @@ -312,14 +318,17 @@ var getCookies = function (uri, format, callback) {

}

return callback(null, output);
db.close(function(err) {
if (!err) {
dbClosed = true;
}
return callback(null, output);
});

});

});

db.close();

});

};
Expand Down

0 comments on commit 4d74164

Please sign in to comment.