Skip to content

Commit

Permalink
Update rsync.js with Windows support
Browse files Browse the repository at this point in the history
* Update rsync.js with Windows support

Add a new function: escapeDirectorySeparator() which used in escapeFileArg() to set directory separator correctly under Windows.
If you use th cygwin's rsync with OpenSSH for Windows (http://www.mls-software.com/opensshd.html) they are using standard linux directory separator and this update can handle directories under Window.
To use rsync under Windows, you need to symlink your directories well (with standard Windows mklink command line tool).

* Update rsync.js

Copied contents of the escapeDirectorySeparator function under escapeFileArg and remove unused function.

* Update input.test.js

Add "should convert windows path under windows" for source and "should convert widows path for destination" for destination test.

* Update input.test.js

Set platform to win32 with safe.

* Update input.test.js

#sourcewin32 and #destinationwin32

* Create inputwin32.test.js

Windows input source and destinatiion testing

* Update input.test.js

Move windows test to inputwin32.test.js

* Update inputwin32.test.js

update to mocha before and after (not beforeAll anf afterAll)

* Update inputwin32.test.js

bugfix: rsync needed
  • Loading branch information
pumuckly authored and Mattijs Hoitink committed Jan 14, 2017
1 parent 4022990 commit 133e4ab
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
12 changes: 11 additions & 1 deletion rsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,17 @@ function escapeShellArg(arg) {
* @return {String} the escaped version of the filename
*/
function escapeFileArg(filename) {
return filename.replace(/(["'`\s\\\(\)\\$])/g,'\\$1');
filename = filename.replace(/(["'`\s\\\(\)\\$])/g,'\\$1');
if (!/(\\\\)/.test(filename)) {
return filename;
}
// Under Windows rsync (with cygwin) and OpenSSH for Windows
// (http://www.mls-software.com/opensshd.html) are using
// standard linux directory separator so need to replace it
if ('win32' === process.platform) {
filename = filename.replace(/\\\\/g,'/').replace(/^["]?[A-Z]\:\//ig,'/');
}
return filename;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/input.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe('input', function () {
});
assertOutputPattern(rsync, / example\\ file.txt manual.pdf \\'special_case\\ 1\\'.rtf/);
});

});

//# destination
Expand Down Expand Up @@ -104,6 +105,7 @@ describe('input', function () {
assertOutputPattern(rsync, /\$some_destination\/$/);
});


});

});
47 changes: 47 additions & 0 deletions tests/inputwin32.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* global describe,it */
"use strict";

var assertOutputPattern = require('./helpers/output').assertOutputPattern;
var Rsync = require('../rsync');

describe('inputwin32', function () {
before(function(){
this.originalPlatform = process.platform;
Object.defineProperty(process, 'platform', {
value: 'win32'
});
});

//# sources under windows
describe('#sourcewin32', function () {
var rsync;

it('should convert windows path under windows',function () {
rsync = Rsync.build({
source: [ 'C:\\home\\username\\develop\\readme.txt' ],
destination: 'themoon'
});
assertOutputPattern(rsync, / \/home\/username\/develop\/readme\.txt /);
});
});

//# destination under win32
describe('#destinationwin32', function () {
var rsync;

it('should convert widows path for destination', function () {
rsync = Rsync.build({
source: [ 'reame.txt' ],
destination: 'C:\\home\\username\\develop\\'
});
assertOutputPattern(rsync, /\/home\/username\/develop\//);
});

});

after(function(){
Object.defineProperty(process, 'platform', {
value: this.originalPlatform
});
});
});

0 comments on commit 133e4ab

Please sign in to comment.