Comparing version 0.1.1 to 0.1.2
@@ -5,5 +5,2 @@ // Design Notes | ||
// - add try/catch logic to sync.setup() | ||
// - add directory creation | ||
// - add delete() function | ||
// - add directory removal | ||
// - add verify() function | ||
@@ -42,2 +39,4 @@ // - add touch() function | ||
remote: [], | ||
mkdir: [], | ||
rmdir: [], | ||
add: [], | ||
@@ -79,6 +78,6 @@ update: [], | ||
// log the results | ||
console.log('Local Files:'); | ||
console.log('Local:'); | ||
console.dir(sync.local); | ||
console.log(); | ||
console.log('Remote Files:'); | ||
console.log('Remote:'); | ||
console.dir(sync.remote); | ||
@@ -94,16 +93,30 @@ console.log(); | ||
console.log('-------------------------------------------------------------'); | ||
// create lookup tebles for easy comparison | ||
var rFiles = helpers.lookupTable(sync.remote); | ||
var lFiles = helpers.lookupTable(sync.local); | ||
// run the comparison | ||
// prepare the directory lists for comparison | ||
var rdirs = sync.remote.dirs; | ||
var ldirs = sync.local.dirs; | ||
// prepare the files lists for comparison | ||
var rFiles = helpers.lookupTable(sync.remote.files); | ||
var lFiles = helpers.lookupTable(sync.local.files); | ||
// compare directories for modifications | ||
rdirs.forEach(function(dir) { | ||
// if a match is found | ||
var lIDX = ldirs.indexOf(dir); | ||
if(lIDX != -1) { | ||
var rIDX = rdirs.indexOf(dir); | ||
ldirs[lIDX] = ''; | ||
rdirs[rIDX] = ''; | ||
} | ||
}); | ||
// compare files for modifications | ||
rFiles.forEach(function(file) { | ||
var lIDX = lFiles.indexOf(file); | ||
// if a match is found | ||
if (lIDX != -1) { | ||
var rIDX = rFiles.indexOf(file); | ||
var lFile = sync.local[lIDX]; | ||
var rFile = sync.remote[rIDX]; | ||
if (helpers.isDifferent(sync.local[lIDX], sync.remote[rIDX])) { | ||
var lFile = sync.local.files[lIDX]; | ||
var rFile = sync.remote.files[rIDX]; | ||
if (helpers.isDifferent(sync.local.files[lIDX], sync.remote.files[rIDX])) { | ||
sync.update.push(file); | ||
} | ||
// mark matches for removal | ||
// mark updates as processed | ||
lFiles[lIDX] = ''; | ||
@@ -113,7 +126,12 @@ rFiles[rIDX] = ''; | ||
}); | ||
// remove matches from local and remote tables | ||
rFiles.forEach(function(file) { | ||
if(file === '') { return; } | ||
sync.remove.push(file); | ||
// process the rest | ||
ldirs.forEach(function(dir) { | ||
if(dir === '') { return; } | ||
sync.mkdir.push(dir); | ||
}); | ||
rdirs = rdirs.reverse(); | ||
rdirs.forEach(function(dir) { | ||
if(dir === '') { return; } | ||
sync.rmdir.push(dir); | ||
}); | ||
lFiles.forEach(function(file) { | ||
@@ -123,8 +141,16 @@ if(file === '') { return; } | ||
}); | ||
rFiles.forEach(function(file) { | ||
if(file === '') { return; } | ||
sync.remove.push(file); | ||
}); | ||
// log the results | ||
console.log('Mkdir:'); | ||
console.dir(sync.mkdir); | ||
console.log('Rmdir:'); | ||
console.dir(sync.rmdir); | ||
console.log('Add:'); | ||
console.dir(sync.add); | ||
console.log('Updates:'); | ||
console.dir(sync.update); | ||
console.log('Add:'); | ||
console.dir(sync.add); | ||
console.log('Remove:'); | ||
@@ -142,2 +168,13 @@ console.dir(sync.remove); | ||
function(callback) { | ||
if (sync.mkdir.length == 0) { callback(null, 'no mkdirs'); return; } | ||
async.mapLimit(sync.mkdir, settings.connections, utils.mkdir, function (err) { | ||
if (err) { | ||
callback(err, 'mkdirs failed'); | ||
} | ||
else { | ||
callback(null, 'mkdirs complete'); | ||
} | ||
}); | ||
}, | ||
function(callback) { | ||
if (sync.add.length == 0) { callback(null, 'no additions'); return; } | ||
@@ -166,4 +203,21 @@ async.mapLimit(sync.add, settings.connections, utils.upload, function (err) { | ||
if (sync.remove.length == 0) { callback(null, 'no removals'); return; } | ||
// TODO: add stuff here | ||
callback(null, 'removals complete'); | ||
async.mapLimit(sync.remove, settings.connections, utils.remove, function (err) { | ||
if (err) { | ||
callback(err, 'removals failed'); | ||
} | ||
else { | ||
callback(null, 'removals complete'); | ||
} | ||
}); | ||
}, | ||
function(callback) { | ||
if (sync.rmdir.length == 0) { callback(null, 'no rmdirs'); return; } | ||
async.mapLimit(sync.rmdir, settings.connections, utils.rmdir, function (err) { | ||
if (err) { | ||
callback(err, 'rmdirs failed'); | ||
} | ||
else { | ||
callback(null, 'rmdirs complete'); | ||
} | ||
}); | ||
} | ||
@@ -218,3 +272,4 @@ ], | ||
walkLocal: function(dir, callback) { | ||
var results = []; | ||
var dirs = []; | ||
var files = []; | ||
// walk the directory | ||
@@ -227,3 +282,3 @@ fs.readdir(dir, function(err, list) { | ||
// exit if all files are processed | ||
if (!file) return callback(null, results); | ||
if (!file) return callback(null, { 'dirs':dirs,'files':files }); | ||
// skip ignore files | ||
@@ -239,4 +294,8 @@ if (settings.ignore.indexOf(file) != -1) { | ||
if (stat.isDirectory()) { | ||
// add the directory to the results | ||
dirs.push(helpers.trimPathRoot(settings.local, path)); | ||
// concat results from recursive calls | ||
utils.walkLocal(path, function(err, res) { // recurse & shit | ||
results = results.concat(res); | ||
dirs = dirs.concat(res.dirs); | ||
files = files.concat(res.files); | ||
next(); | ||
@@ -248,3 +307,3 @@ }); | ||
if (stat.isFile()) { | ||
results.push({ | ||
files.push({ | ||
'id':helpers.trimPathRoot(settings.local, path), | ||
@@ -265,3 +324,4 @@ 'size':stat.size, | ||
walkRemote: function(dir, callback) { | ||
var results = []; | ||
var dirs = []; | ||
var files = []; | ||
// walk the directory | ||
@@ -274,3 +334,3 @@ ftp.ls(dir, function(err, list) { | ||
// exit if all files are processed | ||
if (!file) return callback(null, results); | ||
if (!file) return callback(null, { 'dirs':dirs, 'files':files }); | ||
// skip ignore files | ||
@@ -285,4 +345,8 @@ if (settings.ignore.indexOf(file.name) != -1) { | ||
if (file.type == 1) { | ||
// add the directory to the results | ||
dirs.push(helpers.trimPathRoot(settings.remote, path)); | ||
// concat results from recursive calls | ||
utils.walkRemote(path, function(err, res) { // recurse & shit | ||
results = results.concat(res); | ||
dirs = dirs.concat(res.dirs); | ||
files = files.concat(res.files); | ||
next(); | ||
@@ -294,3 +358,4 @@ }); | ||
if (file.type = 2) { | ||
results.push({ | ||
// add the file to the results | ||
files.push({ | ||
'id':helpers.trimPathRoot(settings.remote, path), | ||
@@ -309,2 +374,30 @@ 'size':+file.size, | ||
mkdir: function(dir, callback) { | ||
var dir = settings.remote + dir; | ||
ftp.raw.mkd(dir, function(err, data) { | ||
if (err) { | ||
console.error(err); | ||
callback(err); | ||
} | ||
else { | ||
console.log(dir + " - created successfuly"); | ||
callback(); | ||
} | ||
}); | ||
}, | ||
rmdir: function(dir, callback) { | ||
var dir = settings.remote + dir; | ||
ftp.raw.rmd(dir, function(err, data) { | ||
if (err) { | ||
console.error(err); | ||
callback(err); | ||
} | ||
else { | ||
console.log(dir + " - deleted successfuly"); | ||
callback(); | ||
} | ||
}); | ||
}, | ||
// upload a file to the remote server | ||
@@ -335,3 +428,13 @@ upload: function(file, callback) { | ||
remove: function(file, callback) { | ||
return; | ||
var file = settings.remote + file; | ||
ftp.raw.dele(file, function(err, data) { | ||
if (err) { | ||
console.error(err); | ||
callback(err); | ||
} | ||
else { | ||
console.log(file + " - deleted successfuly"); | ||
callback(); | ||
} | ||
}); | ||
} | ||
@@ -338,0 +441,0 @@ } |
{ | ||
"name": "ftpsync", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Intelligent file syncronization over FTP", | ||
@@ -5,0 +5,0 @@ "homepage": "http://github.com/evanplaice/node-ftpsync", |
@@ -12,3 +12,3 @@ An FTP synchronization app for NodeJS based on [jsftp](https://npmjs.org/package/jsftp). With an emphasis on speed and simplicity ftpsync aims to fulfull your one-click file deployment needs. | ||
```js | ||
$ node ftpsync --help | ||
$ ftpsync --help | ||
@@ -51,3 +51,3 @@ Usage: ftpsync [options] | ||
"pass":"password", | ||
"connection":"2", | ||
"connections":"2", | ||
"ignore":[ | ||
@@ -67,3 +67,3 @@ ".htaccess" | ||
`node ftpsync` | ||
`ftpsync` | ||
@@ -74,3 +74,3 @@ #### Optional - Logging to a file | ||
`npm ftpsync > ftpsync.log &` | ||
`ftpsync > ftpsync.log &` | ||
@@ -102,22 +102,60 @@ API | ||
#### ftpsync.local[] | ||
#### ftpsync.local{} | ||
The file listing for the local host. Populated by running `collect()`. | ||
The file and directory listings for the local host. | ||
- `ftpsync.local.dirs` - contains a simple list. | ||
Each path represents a local directory. | ||
- `ftpsync.local.files` - contains a list of objects. | ||
Each object in the list represents a file and contains a `id`, `size`, and `time` attribute with the requisite values for that file. | ||
Populated by running `collect()` or `utils.walkLocal()`. | ||
#### ftpsync.remote[] | ||
The file listing for the remote server. Populated by running `collect()`. | ||
The file and directory listings for the remote host. | ||
- `ftpsync.remote.dirs` - contains a simple list. | ||
Each path represents a remote directory. | ||
- `ftpsync.remote.files` - contains a list of objects. | ||
Each object in the list represents a file and contains a `id`, `size`, and `time` attribute with the requisite values for that file. | ||
Populated by running `collect()` or `utils.walkremote()`. | ||
#### ftpsync.mkdir[] | ||
The list of directories queued for creation on the remote server. | ||
Populated by running `consolidate()`. | ||
#### ftpsync.rmdir[] | ||
The list of directories queued for deletion on the remote server. | ||
Populated by running `consolidate()`. | ||
#### ftpsync.add[] | ||
The list of files queued to for addition to the remote server. Populated by running `consolidate()`. | ||
The list of files queued to for addition to the remote server. | ||
Populated by running `consolidate()`. | ||
#### ftpsync.update[] | ||
The list of files queued for update on the remote server. Populated by running `consolidate()`. | ||
The list of files queued for update on the remote server. | ||
Populated by running `consolidate()`. | ||
#### ftpsync.remove[] | ||
The list of files queued for removal from the remote server. Populated by running `consolidate()`. | ||
The list of files queued for removal from the remote server. | ||
Populated by running `consolidate()`. | ||
### Methods | ||
@@ -178,2 +216,2 @@ | ||
See LICENSE. | ||
MIT. See LICENSE. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
23558
6
458
212
0