Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: run Commands when set by "cmds add" cli (#655) #1106

Merged
merged 1 commit into from
Oct 5, 2020
Merged

fix: run Commands when set by "cmds add" cli (#655) #1106

merged 1 commit into from
Oct 5, 2020

Conversation

dannyp11
Copy link
Contributor

@dannyp11 dannyp11 commented Oct 3, 2020

Description

Hello, I came across the exact issue #655 in that when adding cmds via filebrowser cli instead of in web UI, filebrowser fails to run the command due to leading whitespace (eg. input command is "echo hello" but filebrowser will run " echo hello")

To reproduce

rm -f filebrowser.db
filebrowser config init
filebrowser cmds add "before_upload" "echo hello world"
filebrowser -r .

Try to upload 1 file

  • Expected: file is uploaded successfully, hello world is printed to stdout
  • Actual: no such file or directory error due to running " echo hello world" instead of "echo hello world"
2020/10/03 15:00:59 [INFO] Blocking Command: " echo hello world"
2020/10/03 15:00:59 /service-runner: 404 127.0.0.1 fork/exec : no such file or directory

Root cause

  • Settings.Shell is initiated as []string{""} instead of []string{} due to strings.Split() expected behavior
  • that will result in len(Shell) always >= 1
  • that leads to command = append(s.Shell, raw) which is ["", "echo hello world"] which leads to cmd := exec.Command("", "echo", "hello", "world") here
    => runs exec command " echo hello world" instead of "echo hello world"

Testing

  1. Try reproduce step
  2. File is uploaded successfully and "hello world" is printed
2020/10/03 15:03:07 [INFO] Blocking Command: "echo hello world"
hello world

🚨 I have followed all the below:

  • DO make sure you are requesting to pull a topic/feature/bugfix branch (right side). Don't request your master!
  • DO make sure you are making a pull request against the master branch (left side). Also you should start your branch off our master.
  • DO make sure that File Browser can be successfully built. See builds and development.
  • DO make sure that related issues are opened in other repositories. I.e., the frontend, caddy plugins or the web page need to be updated accordingly.
  • AVOID breaking the continuous integration build.

❤️ Thank you!

cmd/config_init.go Outdated Show resolved Hide resolved
@o1egl
Copy link
Member

o1egl commented Oct 4, 2020

Good catch!

@dannyp11
Copy link
Contributor Author

dannyp11 commented Oct 4, 2020

Revision 2

Testing passed

2020/10/04 13:52:28 [INFO] Blocking Command: "echo hello world"
hello world

@dannyp11 dannyp11 requested a review from o1egl October 4, 2020 21:03
@dannyp11
Copy link
Contributor Author

dannyp11 commented Oct 4, 2020

Revision 3

  • Fix same bug in config_set.go
  • Move cmd string split into cmd/utils.go

Testing passed

2020/10/04 14:28:38 [INFO] Blocking Command: "echo hello world"
hello world

Side note

@o1egl why don't we have any unit test? I'm happy to setup simple one in separate PR if the team is ok with it, where can I bring this up?

@o1egl
Copy link
Member

o1egl commented Oct 5, 2020

@dannyp11 I think due to historical reason. I'm trying to add unit test on new code. At the moment I'm working on refactoring which will be released as v3 and after that unit tests will be required for PRs

Copy link
Member

@o1egl o1egl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@o1egl o1egl merged commit 36fb9f5 into filebrowser:master Oct 5, 2020
dr-bonez pushed a commit to Start9Labs/filebrowser that referenced this pull request Oct 7, 2020
@dannyp11 dannyp11 deleted the 655-cmd-leading-whitespace branch October 16, 2020 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants