Permalink
Browse files

Normalising paths and respecting the path name setup on —-remote_base

  • Loading branch information...
bermi committed Apr 30, 2016
1 parent 486e6d4 commit e336917c4b9a6d30c38ff0c50fae2f7748ee3380
Showing with 17 additions and 15 deletions.
  1. +2 −7 README.md
  2. +15 −8 lib/webdav_sync.js
View
@@ -38,9 +38,6 @@ Syncing /var/src/code with https://user:pass@demandware.com/webdav/cartridge/
webdav-sync --local_base /var/src/code --remote_base "https://user:pass@demandware.com/webdav/"
webdav-sync --local_base /Users/bermi/personal/code/webdav-sync --remote_base "http://192.168.99.100:8888/webdav/" --username test --password test --verbose
#### From node.js
You can also include webdav-sync into your node app
@@ -55,9 +52,6 @@ You can also include webdav-sync into your node app
sync.start();
### Development
Simply execute `cake dev` to start continuous compilation. You may also want to run `npm link` so that whenever you call `require('webdav-sync')` it will always point to the current dev version.
### Change log
@@ -66,11 +60,12 @@ Simply execute `cake dev` to start continuous compilation. You may also want to
- 0.3.0: Cleanup and --verbose flag added
- 0.4.0: Minor update due to change in stdout: File transfer fixes, connection test, transfer status icons
- 0.4.4: Added options --username & --password as option for secure login (useful for problematic usernames/passwords with special characters...)
- 0.5.0: Updated npm dependencies
### TODO
* Remove curl dependencies
* Add tests
* Add tests, right now it's been manually tested using [https://hub.docker.com/r/morrisjobke/webdav/]()
### License
View
@@ -28,11 +28,12 @@ var __indexOf = [].indexOf || function (item) {
return -1;
};
var exec, util, colors, fs, watch, url; //libraries
var exec, util, colors, normalize, fs, watch, url; //libraries
watch = require("watch");
fs = require("fs");
colors = require("colors");
util = require("util");
normalize = require("path").normalize;
exec = require("child_process").exec;
url = require("url");
@@ -83,6 +84,7 @@ module.exports = function (options) {
currLine++;
console.log((new Date()).toString().underline);
currLine++;
command += " --verbose";
console.log(command.yellow);
}
@@ -112,6 +114,10 @@ module.exports = function (options) {
processed["w" + path + stats.mtime] = currLine;
rel_path = path.replace(options.local_base, "");
rel_path = normalize(url.parse(options.remote_base).path +
path.replace(options.local_base, ""));
destination = url.resolve(options.remote_base, rel_path);
//ignore it?
@@ -120,10 +126,8 @@ module.exports = function (options) {
}
if (stats.isFile()) {
command = options.curl + ' -T "' + path + '" "' + destination + '" ';
} else {
if (stats.isDirectory()) {
command = options.curl + ' -X MKCOL "' + destination + '" ';
}
} else if (stats.isDirectory()) {
command = options.curl + ' -X MKCOL "' + destination + '" ';
}
if (command != null) {
message = "[created] ".bold.green + rel_path.green;
@@ -144,18 +148,21 @@ module.exports = function (options) {
processed["m" + path + stats.mtime] = currLine; //remember that we modified path at mtime...
rel_path = path.replace(options.local_base, "");
rel_path = normalize(url.parse(options.remote_base).path +
path.replace(options.local_base, ""));
destination = url.resolve(options.remote_base, rel_path);
if (ignoreFile(rel_path)) {
return;
}
//BEN: does this NOT work on folder modifications?
if (stats.isFile()) {
command = options.curl + ' -T "' + path + '" ' + destination;
} else if (stats.isDirectory()) {
command = options.curl + ' -X MKCOL ' + destination;
}
if (command != null) {
if (command != null) {
message = "[changed] ".bold.cyan + rel_path.cyan;
return run(command, message);
}

0 comments on commit e336917

Please sign in to comment.