Giter VIP home page Giter VIP logo

Comments (15)

AlbertoGP avatar AlbertoGP commented on May 18, 2024

Hi, I think your problem might be caused by the option value escaping.
I've prepared a fix for that in pull request #13
Does it solve the issue?

from node-rsync.

AlbertoGP avatar AlbertoGP commented on May 18, 2024

I've done some tests with a similar command and in my case I was getting error code 12 without the fix.
However, there is yet another issue: if you want to use a file name pattern like "*.gz" you'll have to expand it on your own using something like https://www.npmjs.org/package/glob

It would have worked in older versions of node-rsync because, as it used exec() to launch the rsync command, it was being parsed and expanded by the shell, but now using spawn() instead there is no shell to do that work for you.

from node-rsync.

mattijs avatar mattijs commented on May 18, 2024

The first thing that sprung to my mind was path expansion. It probably does not work with the shell the command is run in. Like @AlbertoGP says you basically have to expand the paths in your node script manually and use a list of files instead of a "globbed" path.

I'll take a look at your PR @AlbertoGP because shell escaping should work properly.

@akayami What shell do you use? (bash/zsh/fish?)

from node-rsync.

AlbertoGP avatar AlbertoGP commented on May 18, 2024

The point is that spawn does not use any shell.

You might assume that node's exec and spawn correspond to the POSIX function families exec* and spawn*, but if you look closely you'll notice that there is no exec* that takes the whole command line as argument, but always each argument separately just like spawn*:
exec_: http://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html
spawn_: http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawn.html

The documentation for exec says:
http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

Runs a command in a shell and buffers the output.

If you look in spawn, there is no mention of shells. I guess it could be more explicit to avoid confusions.
http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options

Node's child_process.exec() is more similar to system():
http://pubs.opengroup.org/onlinepubs/9699919799/functions/system.html

I thought they might use that function, but it turns out that they just launch the shell executable with your command line as an argument as described in the link above for system(). You can see it in node's source code:
https://github.com/joyent/node/blob/937e2e351b2450cf1e9c4d8b3e1a4e2a2def58bb/lib/child_process.js#L589

Thus it does not matter what shell you have selected in your user account: it'll always use cmd.exe in Windows and /bin/sh anywhere else.

from node-rsync.

mattijs avatar mattijs commented on May 18, 2024

@AlbertoGP wow, good info, usefull to know. I hadn't looked at the source yet.

After some testing I think the error 14 is due to the escaping of the --rsh option, making it very related to #12. I'm working on fixing the escaping to fix #11 and #12.

from node-rsync.

AlbertoGP avatar AlbertoGP commented on May 18, 2024

If you mean the function escapeShellArg() yes, removing the quoting there solves some simple cases, and others have done it as a quick fix: (that's also the first thing I tried)
https://github.com/yottagroup/node-rsync/commit/8423412111f1642728da858258ddc7c403e8cfac
https://github.com/mattijs/node-rsync/network

from node-rsync.

AlbertoGP avatar AlbertoGP commented on May 18, 2024

Another alternative is to launch the whole command line under a shell.
See PR #15, which is much less invasive than #13 and gets us file name globbing for free, just like in the good old days of using exec().

from node-rsync.

mattijs avatar mattijs commented on May 18, 2024

@AlbertoGP What does removing the escapeShellArg() not fix? I don't see a real difference in outcome with your PR #13. The outcome is the same as these changes: c2e4d82

from node-rsync.

AlbertoGP avatar AlbertoGP commented on May 18, 2024

You already saw it, but in case someone arrives here from a search engine, the answer is at #13 (comment)
In short, it's short options with arguments.

from node-rsync.

mattijs avatar mattijs commented on May 18, 2024

@akayami master has been updated to include fixes for your problem. Could you retest your command with the master code to see if it works?

from node-rsync.

akayami avatar akayami commented on May 18, 2024

@mattijs Hi. Your fix works perfectly. Thank you very much !

Do you need to push it in some way to be available using NPM ? I have no clue how that part works, but I would like to be able to specify the correct version in my package.json file.

from node-rsync.

mattijs avatar mattijs commented on May 18, 2024

@akayami I'll publish a new version to NPM as soon as possible so you can set a version in your dependencies.

If you want to use the latest version already you can set the version in your package.json to the master branch. This will make you use the latest version (see https://www.npmjs.org/doc/files/package.json.html#Git-URLs-as-Dependencies).

from node-rsync.

heyvito avatar heyvito commented on May 18, 2024

Just subscribed to notifications on this issue. I'm having the very same problem, but when using sshpass as shell. Also looking forward the NPM package update.

Thank you, guys!

from node-rsync.

mattijs avatar mattijs commented on May 18, 2024

I just released v0.3.0 as a github tag (https://github.com/mattijs/node-rsync/tree/v0.3.0) and published a new version to NPM. You can set your package.json versions to 0.3.0 πŸ‘

from node-rsync.

heyvito avatar heyvito commented on May 18, 2024

Awesome, Mattijs. Thank you very much! :shipit:

from node-rsync.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.