imjp94 / gd-plug

Minimal plugin manager for Godot
MIT License
209 stars 15 forks source link

Fails to install when there are spaces in project directory name #6

Closed lihop closed 3 years ago

lihop commented 3 years ago

Platform/versions: Linux, Godot 3.3.2-stable, gd-plug 0.1.1 Steps to reproduce:

  1. Create new project with the default name "New Game Project" 2021-07-16-185130_498x162_scrot
  2. Install gd-plug from Asset Lib.
  3. Add a plug.gd file with some plugin. For example:
    
    extends "res://addons/gd-plug/plug.gd"

func _plugging(): plug("bitwes/Gut")

4. Run install command:

godot --no-window -s plug.gd install

**Expected**: Install plugins.
**Actual**: Fails with:

Failed to download Gut Failed to install plugin Gut with error code 1


Output when running install command with debug logging:

Godot Engine v3.3.2.stable.custom_build - https://godotengine.org WARNING: initialize: XOpenIM failed At: platform/x11/os_x11.cpp:200. WARNING: initialize: XCreateIC couldn't create xic At: platform/x11/os_x11.cpp:508. OpenGL ES 3.0 Renderer: NVIDIA GeForce GTX 1060/PCIe/SSE2 OpenGL ES Batching: ON

cmdline_args: [install, debug] Plug start Installation config loaded Plug: {branch:, commit:, dev:False, exclude:[...], include:[], install_root:, name:Gut, on_updated:, plug_dir:res://.plugged/Gut, tag:, url:https://git::@github.com/bitwes/Gut.git} Installing... Execute task [SceneTree:1180].install_plugin() Request quit declined, threadpool is still running Installing plugin Gut... Downloading Gut from https://git::@github.com/bitwes/Gut.git... Cloning from https://git::@github.com/bitwes/Gut.git to /home/leroy/New Game Project/.plugged/Gut... Execute "cd /home/leroy/New Game Project/.plugged/Gut && git clone --depth=1 --progress https://git::@github.com/bitwes/Gut.git /home/leroy/New Game Project/.plugged/Gut" Execution ended(code:1): [] Failed to clone from https://git::@github.com/bitwes/Gut.git Failed to download Gut Failed to install plugin Gut with error code 1 Execution finished [SceneTree:1180].install_plugin() All thread finished Plugged config saved Finished, elapsed 0.163s

**Cause**: I think it is caused by the spaces in the directory name which are not escaped escaped with "\\". Example:

[leroy@laptop ~]$ cd /home/leroy/New Game Project/ bash: cd: too many arguments [leroy@laptop ~]$ echo $? 1 [leroy@laptop ~]$ cd /home/leroy/New\ Game\ Project/ [leroy@laptop New Game Project]$ echo $? 0


Generally, I never create directories with spaces because of issues like these, but in this case I used the default project name as I wanted to quickly test something and stumbled upon this error.
imjp94 commented 3 years ago

Thanks for the detailed bug report, and, yes it is caused by spaces in directory name. I managed to solve this by enclosing the directory name with double-quote in this commit(d3f828251469f977cbfffd85c92bbcecf672a924). It works on my machine(Windows), would you mind to test it for me?

lihop commented 3 years ago

Wow, thanks for the prompt response!

I tried with that commit but still get the same error, however it works when I use single rather than double quotes. I also had to add quotes around cwd in the cd command:

diff --git a/addons/gd-plug/plug.gd b/addons/gd-plug/plug.gd
index 5056d5b..ae2a675 100644
--- a/addons/gd-plug/plug.gd
+++ b/addons/gd-plug/plug.gd
@@ -696,7 +696,7 @@ class _GitExecutable extends Reference:
        logger = p_logger

    func _execute(command, blocking=true, output=[], read_stderr=false):
-       var cmd = "cd %s && %s" % [cwd, command]
+       var cmd = "cd '%s' && %s" % [cwd, command]
        # NOTE: OS.execute() seems to ignore read_stderr
        var exit = FAILED
        match OS.get_name():
@@ -726,9 +726,9 @@ class _GitExecutable extends Reference:
        var branch = args.get("branch", "")
        var tag = args.get("tag", "")
        var commit = args.get("commit", "")
-       var command = "git clone --depth=1 --progress \"%s\" \"%s\"" % [src, dest]
+       var command = "git clone --depth=1 --progress '%s' '%s'" % [src, dest]
        if branch or tag:
-           command = "git clone --depth=1 --single-branch --branch %s \"%s\" \"%s\"" % [branch if branch else tag, src, dest]
+           command = "git clone --depth=1 --single-branch --branch %s '%s' '%s'" % [branch if branch else tag, src, dest]
        elif commit:
            return clone_commit(src, dest, commit)
        var exit = _execute(command, true, output)
@@ -768,7 +768,7 @@ class _GitExecutable extends Reference:
    func remote_add(name, src):
        logger.debug("Adding remote %s@%s..." % [name, src])
        var output = []
-       var exit = _execute("git remote add %s \"%s\"" % [name, src], true, output)
+       var exit = _execute("git remote add %s '%s'" % [name, src], true, output)
        logger.debug("Successfully added remote" if exit == OK else "Failed to add remote")
        return {"exit": exit, "output": output}

Apart from single quotes, it also works with escaped double quote escapes: \\\"%s\\\".

imjp94 commented 3 years ago

Both single quotes and escaped double quote escapes doesn't work with cmd on Windows Screenshot 2021-07-16 233730 gd-plug's output with single quote

cmdline_args: [install, debug]
Plug start
Installation config loaded
Plug: {branch:, commit:, dev:False, exclude:[...], include:[], install_root:, name:Gut, on_updated:, plug_dir:res://.plugged/Gut, tag:, url:https://git::@github.com/bitwes/Gut.git}
Installing...
Execute task [SceneTree:1180].install_plugin()
Installing plugin Gut...
Request quit declined, threadpool is still running
Downloading Gut from https://git::@github.com/bitwes/Gut.git...
Cloning from https://git::@github.com/bitwes/Gut.git to D:/Godot/gd-plug/.plugged/Gut...
Execute "cd 'D:/Godot/gd-plug/.plugged/Gut' && 'git clone --depth=1 --progress 'https://git::@github.com/bitwes/Gut.git' 'D:/Godot/gd-plug/.plugged/Gut'' 2> nul"
The filename, directory name, or volume label syntax is incorrect.
Execution ended(code:1): []
Failed to clone from https://git::@github.com/bitwes/Gut.git
Failed to download Gut
Failed to install plugin Gut with error code 1
Execution finished [SceneTree:1180].install_plugin()
All thread finished
Plugged config saved
Finished, elapsed 0.583s

gd-plug's output with escaped double quote escapes

cmdline_args: [install, debug]
Plug start
Installation config loaded
Plug: {branch:, commit:, dev:False, exclude:[...], include:[], install_root:, name:Gut, on_updated:, plug_dir:res://.plugged/Gut, tag:, url:https://git::@github.com/bitwes/Gut.git}
Installing...
Execute task [SceneTree:1180].install_plugin()
Installing plugin Gut...
Request quit declined, threadpool is still running
Downloading Gut from https://git::@github.com/bitwes/Gut.git...
Cloning from https://git::@github.com/bitwes/Gut.git to D:/Godot/gd-plug/.plugged/Gut...
Execute "cd \"D:/Godot/gd-plug/.plugged/Gut\" && \"git clone --depth=1 --progress \"https://git::@github.com/bitwes/Gut.git\" \"D:/Godot/gd-plug/.plugged/Gut\"\" 2> nul"
The filename, directory name, or volume label syntax is incorrect.
Execution ended(code:1): []
Failed to clone from https://git::@github.com/bitwes/Gut.git
Failed to download Gut
Failed to install plugin Gut with error code 1
Execution finished [SceneTree:1180].install_plugin()
All thread finished
Plugged config saved
Finished, elapsed 0.606s

I just updated the commit(4e6dc70bbe949426503a5a134e60d563de63a45d) to enclosed cwd with double-quote as well, can you try again?

lihop commented 3 years ago

Output with that commit reports a different error:

[leroy@laptop New Game Project]$ godot --no-window -s plug.gd install debug
Godot Engine v3.3.2.stable.custom_build - https://godotengine.org
OpenGL ES 3.0 Renderer: NVIDIA GeForce GTX 1060/PCIe/SSE2
OpenGL ES Batching: ON

cmdline_args: [install, debug]
Plug start
Make dir %s for plugin installation
Installation config not found
Plug: {branch:, commit:, dev:False, exclude:[...], include:[], install_root:, name:Gut, on_updated:, plug_dir:res://.plugged/Gut, tag:, url:https://git::@github.com/bitwes/Gut.git}
Installing...
Execute task [SceneTree:1180].install_plugin() 
Request quit declined, threadpool is still running
Installing plugin Gut...
Downloading Gut from https://git::@github.com/bitwes/Gut.git...
Cloning from https://git::@github.com/bitwes/Gut.git to /home/leroy/New Game Project/.plugged/Gut...
Execute "cd "/home/leroy/New Game Project/.plugged/Gut" && git clone --depth=1 --progress "https://git::@github.com/bitwes/Gut.git" "/home/leroy/New Game Project/.plugged/Gut""
Execution ended(code:0): []
Successfully cloned from https://git::@github.com/bitwes/Gut.git
Successfully download Gut
Failed to access path: res://.plugged/Gut
Installing files for Gut...
Failed to access path: res://.plugged/Gut
Installed 0 file for Gut
Execution finished [SceneTree:1180].install_plugin() 
All thread finished
Plugged config saved
Finished, elapsed 0.159s
[leroy@laptop New Game Project]$ ls addons/
gd-plug
[leroy@laptop New Game Project]$ ls .plugged/
index.cfg
lihop commented 3 years ago

Disregard that last output. At some point during testing the directory /home/leroy/New got created. When I delete that directory this is the output (same as before):

[leroy@laptop New Game Project]$ godot --no-window -s plug.gd install debug
Godot Engine v3.3.2.stable.custom_build - https://godotengine.org
OpenGL ES 3.0 Renderer: NVIDIA GeForce GTX 1060/PCIe/SSE2
OpenGL ES Batching: ON

cmdline_args: [install, debug]
Plug start
Installation config loaded
Plug: {branch:, commit:, dev:False, exclude:[...], include:[], install_root:, name:Gut, on_updated:, plug_dir:res://.plugged/Gut, tag:, url:https://git::@github.com/bitwes/Gut.git}
Installing...
Execute task [SceneTree:1180].update_plugin() 
Request quit declined, threadpool is still running
Fetching origin...
Execute "cd '/home/leroy/New Game Project/.plugged/Gut' && git fetch origin"
Execution ended(code:1): []
Failed to fetch
Gut up to date
Execution finished [SceneTree:1180].update_plugin() 
All thread finished
Plugged config saved
Finished, elapsed 0.158s
imjp94 commented 3 years ago

This is really weird, both double quote and single quote are not working on Ubuntu

cmdline_args: [install, debug]
Plug start
Installation config loaded
Plug: {branch:, commit:, dev:False, exclude:[...], include:[], install_root:, name:Gut, on_updated:, plug_dir:res://.plugged/Gut, tag:, url:https://git::@github.com/bitwes/Gut.git}
Installing...
Execute task [SceneTree:1180].install_plugin() 
Request quit declined, threadpool is still running
Installing plugin Gut...
Downloading Gut from https://git::@github.com/bitwes/Gut.git...
Cloning from https://git::@github.com/bitwes/Gut.git to /home/ubuntu/Godot/New Game Project/.plugged/Gut...
Execute "cd "/home/ubuntu/Godot/New Game Project/.plugged/Gut" && git clone --depth=1 --progress "https://git::@github.com/bitwes/Gut.git" "/home/ubuntu/Godot/New Game Project/.plugged/Gut""
Execution ended(code:1): []
Failed to clone from https://git::@github.com/bitwes/Gut.git
Failed to download Gut
Failed to install plugin Gut with error code 1
Execution finished [SceneTree:1180].install_plugin() 
All thread finished
Plugged config saved
Finished, elapsed 6.990s
cmdline_args: [install, debug]
Plug start
Installation config loaded
Plug: {branch:, commit:, dev:False, exclude:[...], include:[], install_root:, name:Gut, on_updated:, plug_dir:res://.plugged/Gut, tag:, url:https://git::@github.com/bitwes/Gut.git}
Installing...
Execute task [SceneTree:1180].install_plugin() 
Request quit declined, threadpool is still running
Installing plugin Gut...
Downloading Gut from https://git::@github.com/bitwes/Gut.git...
Cloning from https://git::@github.com/bitwes/Gut.git to /home/ubuntu/Godot/New Game Project/.plugged/Gut...
Execute "cd '/home/ubuntu/Godot/New Game Project/.plugged/Gut' && git clone --depth=1 --progress 'https://git::@github.com/bitwes/Gut.git' '/home/ubuntu/Godot/New Game Project/.plugged/Gut'"
Execution ended(code:127): []
Failed to clone from https://git::@github.com/bitwes/Gut.git
Failed to download Gut
Failed to install plugin Gut with error code 127
Execution finished [SceneTree:1180].install_plugin() 
All thread finished
Plugged config saved
Finished, elapsed 7.100s
lihop commented 3 years ago

Do you have git installed on ubuntu? I see the error code is 127 which is a "command not found" error.

imjp94 commented 3 years ago

Ops, I forgot to install git

imjp94 commented 3 years ago

Finally got it working on both Windows and Ubuntu. #7

Conclusion: Technically, double-quotes should works on any platform(cd "Directory With Spaces" should works anywhere), but the problem is that gd-plug executing command through cmd /c {command}(Window) or bash -c {command}(Linux) and that's where the tricky part as both cmd and bash behave differently. While cmd /c "cd "Directory With Spaces"" is a valid command, bash disagree. While bash -c "cd 'Directory With Spaces'" is a valid command, cmd disagree(in fact, cmd doesn't accept single quote at all).

There's simply no one solution for both platform, so I ended up always enclose directory with spaces with single-quotes(which works well in Linux), and always replace them by double-quotes in Windows.

imjp94 commented 3 years ago

@lihop can you test if #7 works on your machine?