Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 133e4ab

Browse files
pumucklyMattijs Hoitink
authored and
Mattijs Hoitink
committed
Update rsync.js with Windows support
* 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
1 parent 4022990 commit 133e4ab

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

rsync.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,17 @@ function escapeShellArg(arg) {
10171017
* @return {String} the escaped version of the filename
10181018
*/
10191019
function escapeFileArg(filename) {
1020-
return filename.replace(/(["'`\s\\\(\)\\$])/g,'\\$1');
1020+
filename = filename.replace(/(["'`\s\\\(\)\\$])/g,'\\$1');
1021+
if (!/(\\\\)/.test(filename)) {
1022+
return filename;
1023+
}
1024+
// Under Windows rsync (with cygwin) and OpenSSH for Windows
1025+
// (http://www.mls-software.com/opensshd.html) are using
1026+
// standard linux directory separator so need to replace it
1027+
if ('win32' === process.platform) {
1028+
filename = filename.replace(/\\\\/g,'/').replace(/^["]?[A-Z]\:\//ig,'/');
1029+
}
1030+
return filename;
10211031
}
10221032

10231033
/**

tests/input.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ describe('input', function () {
6767
});
6868
assertOutputPattern(rsync, / example\\ file.txt manual.pdf \\'special_case\\ 1\\'.rtf/);
6969
});
70+
7071
});
7172

7273
//# destination
@@ -104,6 +105,7 @@ describe('input', function () {
104105
assertOutputPattern(rsync, /\$some_destination\/$/);
105106
});
106107

108+
107109
});
108110

109111
});

tests/inputwin32.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* global describe,it */
2+
"use strict";
3+
4+
var assertOutputPattern = require('./helpers/output').assertOutputPattern;
5+
var Rsync = require('../rsync');
6+
7+
describe('inputwin32', function () {
8+
before(function(){
9+
this.originalPlatform = process.platform;
10+
Object.defineProperty(process, 'platform', {
11+
value: 'win32'
12+
});
13+
});
14+
15+
//# sources under windows
16+
describe('#sourcewin32', function () {
17+
var rsync;
18+
19+
it('should convert windows path under windows',function () {
20+
rsync = Rsync.build({
21+
source: [ 'C:\\home\\username\\develop\\readme.txt' ],
22+
destination: 'themoon'
23+
});
24+
assertOutputPattern(rsync, / \/home\/username\/develop\/readme\.txt /);
25+
});
26+
});
27+
28+
//# destination under win32
29+
describe('#destinationwin32', function () {
30+
var rsync;
31+
32+
it('should convert widows path for destination', function () {
33+
rsync = Rsync.build({
34+
source: [ 'reame.txt' ],
35+
destination: 'C:\\home\\username\\develop\\'
36+
});
37+
assertOutputPattern(rsync, /\/home\/username\/develop\//);
38+
});
39+
40+
});
41+
42+
after(function(){
43+
Object.defineProperty(process, 'platform', {
44+
value: this.originalPlatform
45+
});
46+
});
47+
});

0 commit comments

Comments
 (0)