Skip to content

Commit

Permalink
Merge 3422efb into bb7f26c
Browse files Browse the repository at this point in the history
  • Loading branch information
Amoki committed Aug 22, 2014
2 parents bb7f26c + 3422efb commit 2b8a388
Show file tree
Hide file tree
Showing 17 changed files with 368 additions and 631 deletions.
9 changes: 5 additions & 4 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"trailing" : true,
"unused" : true,
"loopfunc" : true,

"asi" : false,
"boss" : false,
"debug" : false,
Expand All @@ -43,7 +43,7 @@
"sub" : false,
"supernew" : false,
"validthis" : false,

"browser" : false,
"couch" : false,
"devel" : false,
Expand All @@ -55,17 +55,18 @@
"prototypejs" : false,
"rhino" : false,
"wsh" : false,

"nomen" : false,
"onevar" : false,
"passfail" : false,
"white" : false,

"maxerr" : 100,
"predef" : [
"describe",
"it",
"after",
"afterEach",
"before",
"beforeEach"
],
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ before_script:
script:
- npm test
after_script:
- NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
- NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- --recursive -R spec -t 10000 && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
43 changes: 24 additions & 19 deletions bin/anyfetch-file-watcher
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

var fs = require('fs');
var read = require("read");
var savePendingFiles = require('../lib/helpers/cursor').savePendingFiles;
var async = require("async");

var start = require('../lib');
var filewatcher = require('../lib');

if (process.argv.length < 3) {
console.warn("You have to provide a directory");
Expand All @@ -19,21 +19,26 @@ if (!fs.lstatSync(process.argv[2]).isDirectory()) {
process.exit(1);
}


if (!process.argv[3]) {
read({prompt: 'Token: ', silent: true}, function(err, token) {
start(process.argv[2], token, function() {});
});
}
else {
start(process.argv[2], process.argv[3], function() {});
}

process.on('SIGINT', function() {
savePendingFiles(process.argv[2]);
process.exit(0);
});
process.on('SIGTERM', function() {
savePendingFiles(process.argv[2]);
process.exit(0);
async.waterfall([
function populateVariables(cb) {
if (!process.argv[3]) {
read({prompt: 'Token: ', silent: true}, function(err, token) {
filewatcher(process.argv[3], token, cb);
});
}
else {
filewatcher(process.argv[3], process.argv[2], cb);
}
},
function sendFiles(cb) {
filewatcher.sendNewOrUpdatedFiles(cb);
},
function watchFiles(cb) {
filewatcher.watch();
cb();
}
], function(err) {
if(err){
throw err;
}
});
175 changes: 0 additions & 175 deletions lib/helpers/cursor.js

This file was deleted.

17 changes: 6 additions & 11 deletions lib/helpers/list-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var async = require('async');
var path = require("path");
var fs = require("fs");


var print = function(string) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
Expand All @@ -25,7 +24,7 @@ var getDeletedFiles = function(oldCursor, newCursor) {
};

var getCursorFromDirectory = function(cb) {
// Generate an object with files of the directory passed as argument
// Generate an object with files of the watched directory
// {
// '/a/file/somewhere': lastUpdateOfThisFile,
// '/another/file/somewhere': anotherDate
Expand All @@ -37,7 +36,7 @@ var getCursorFromDirectory = function(cb) {
function readDir(cb) {
fs.readdir(task.dir, cb);
},
function(files, cb) {
function findFiles(files, cb) {
async.map(files, function(nameOfFile, cb) {
var file = path.join(task.dir, nameOfFile);
// Recursive call for directory
Expand Down Expand Up @@ -79,15 +78,11 @@ var getCursorFromDirectory = function(cb) {
};
};

module.exports.retrieveFiles = function retrieveFiles(oldCursor, cb) {
module.exports.retrieveFiles = function retrieveFiles(cb) {
// Update documents from provider
// Compare cursor and the file on the disk
// If the files has been updated we add the file in the files to upload

if(!oldCursor) {
// First run, cursor is empty.
oldCursor = {};
}
var filesToUpload = {};

getCursorFromDirectory(function(err, filesOnDisk) {
Expand All @@ -96,16 +91,16 @@ module.exports.retrieveFiles = function retrieveFiles(oldCursor, cb) {
}

for(var file in filesOnDisk) {
if(!oldCursor[file]) {
if(!GLOBAL.CURSOR[file]) {
// File was added since last run
filesToUpload[file] = filesOnDisk[file];
}
else if(oldCursor[file] < filesOnDisk[file]) {
else if(GLOBAL.CURSOR[file] < filesOnDisk[file]) {
// File updated since last run
filesToUpload[file] = filesOnDisk[file];
}
}
var filesToDelete = getDeletedFiles(oldCursor, filesOnDisk);
var filesToDelete = getDeletedFiles(GLOBAL.CURSOR, filesOnDisk);
cb(null, filesToUpload, filesToDelete);
});
};
Expand Down

0 comments on commit 2b8a388

Please sign in to comment.