From c17c4de9b0738e439846914071fc04c6b4ca9ef8 Mon Sep 17 00:00:00 2001 From: BeziCZ Date: Mon, 17 Feb 2025 14:22:44 +0100 Subject: [PATCH] Simplify shell command execution --- cmd/config.go | 2 +- cmd/config_init.go | 2 +- cmd/config_set.go | 2 +- cmd/root.go | 2 +- frontend/src/types/settings.d.ts | 2 +- frontend/src/views/settings/Global.vue | 14 +++++--------- http/settings.go | 2 +- http/tus_handlers.go | 2 +- runner/parser.go | 4 ++-- settings/settings.go | 2 +- settings/storage.go | 4 ++-- 11 files changed, 17 insertions(+), 21 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index de55c28e..3d3f4255 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -145,7 +145,7 @@ func printSettings(ser *settings.Server, set *settings.Settings, auther auth.Aut fmt.Fprintf(w, "Sign up:\t%t\n", set.Signup) fmt.Fprintf(w, "Create User Dir:\t%t\n", set.CreateUserDir) fmt.Fprintf(w, "Auth method:\t%s\n", set.AuthMethod) - fmt.Fprintf(w, "Shell:\t%s\t\n", strings.Join(set.Shell, " ")) + fmt.Fprintf(w, "Shell:\t%s\t\n", set.Shell) fmt.Fprintln(w, "\nBranding:") fmt.Fprintf(w, "\tName:\t%s\n", set.Branding.Name) fmt.Fprintf(w, "\tFiles override:\t%s\n", set.Branding.Files) diff --git a/cmd/config_init.go b/cmd/config_init.go index 60a0f37b..64934e2f 100644 --- a/cmd/config_init.go +++ b/cmd/config_init.go @@ -32,7 +32,7 @@ override the options.`, Key: generateKey(), Signup: mustGetBool(flags, "signup"), CreateUserDir: mustGetBool(flags, "create-user-dir"), - Shell: convertCmdStrToCmdArray(mustGetString(flags, "shell")), + Shell: mustGetString(flags, "shell"), AuthMethod: authMethod, Defaults: defaults, Branding: settings.Branding{ diff --git a/cmd/config_set.go b/cmd/config_set.go index 23ff7e1b..40d228c1 100644 --- a/cmd/config_set.go +++ b/cmd/config_set.go @@ -48,7 +48,7 @@ you want to change. Other options will remain unchanged.`, case "auth.method": hasAuth = true case "shell": - set.Shell = convertCmdStrToCmdArray(mustGetString(flags, flag.Name)) + set.Shell = mustGetString(flags, flag.Name) case "create-user-dir": set.CreateUserDir = mustGetBool(flags, flag.Name) case "branding.name": diff --git a/cmd/root.go b/cmd/root.go index 59329c5c..b4842125 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -344,7 +344,7 @@ func quickSetup(flags *pflag.FlagSet, d pythonData) { RetryCount: settings.DefaultTusRetryCount, }, Commands: nil, - Shell: nil, + Shell: "", Rules: nil, } diff --git a/frontend/src/types/settings.d.ts b/frontend/src/types/settings.d.ts index a2c19f76..d16c7b35 100644 --- a/frontend/src/types/settings.d.ts +++ b/frontend/src/types/settings.d.ts @@ -6,7 +6,7 @@ interface ISettings { rules: any[]; branding: SettingsBranding; tus: SettingsTus; - shell: string[]; + shell: string; commands: SettingsCommand; } diff --git a/frontend/src/views/settings/Global.vue b/frontend/src/views/settings/Global.vue index 0b055ee2..4cd51558 100644 --- a/frontend/src/views/settings/Global.vue +++ b/frontend/src/views/settings/Global.vue @@ -296,12 +296,7 @@ const save = async () => { if (settings.value === null) return false; let newSettings: ISettings = { ...settings.value, - shell: - settings.value?.shell - .join(" ") - .trim() - .split(" ") - .filter((s: string) => s !== "") ?? [], + shell: settings.value?.shell?.trim() ?? "", // Change this to a string commands: {}, }; @@ -309,7 +304,6 @@ const save = async () => { keyof SettingsCommand >; for (const key of keys) { - // not sure if we can safely assume non-null const newValue = commandObject.value[key]; if (!newValue) continue; @@ -321,7 +315,9 @@ const save = async () => { .filter((cmd: string) => cmd !== ""); } } - newSettings.shell = shellValue.value.split("\n"); + + // Update this line to assign the string directly, without splitting + newSettings.shell = shellValue.value.trim(); if (newSettings.branding.theme !== getTheme()) { setTheme(newSettings.branding.theme); @@ -386,7 +382,7 @@ onMounted(async () => { originalSettings.value = original; settings.value = newSettings; - shellValue.value = newSettings.shell.join("\n"); + shellValue.value = newSettings.shell; } catch (err) { if (err instanceof Error) { error.value = err; diff --git a/http/settings.go b/http/settings.go index de3f22ad..81f3eee2 100644 --- a/http/settings.go +++ b/http/settings.go @@ -16,7 +16,7 @@ type settingsData struct { Rules []rules.Rule `json:"rules"` Branding settings.Branding `json:"branding"` Tus settings.Tus `json:"tus"` - Shell []string `json:"shell"` + Shell string `json:"shell"` Commands map[string][]string `json:"commands"` } diff --git a/http/tus_handlers.go b/http/tus_handlers.go index 773b3d0d..f9d0bbbd 100644 --- a/http/tus_handlers.go +++ b/http/tus_handlers.go @@ -157,7 +157,7 @@ func tusPatchHandler() handleFunc { w.Header().Set("Upload-Offset", strconv.FormatInt(uploadOffset+bytesWritten, 10)) - if bytesWritten < int64(d.Settings.Tus.ChunkSize) { + if uint64(bytesWritten) < (d.Settings.Tus.ChunkSize) { err = d.RunAfterHook("upload", r.URL.Path, "", d.user) if err != nil { return errToStatus(err), err diff --git a/runner/parser.go b/runner/parser.go index 8161a6e5..a8ae9342 100644 --- a/runner/parser.go +++ b/runner/parser.go @@ -12,7 +12,7 @@ import ( func ParseCommand(s *settings.Settings, raw string) ([]string, error) { var command []string - if len(s.Shell) == 0 || s.Shell[0] == "" { + if s.Shell == "" { cmd, args, err := SplitCommandAndArgs(raw) if err != nil { return nil, err @@ -26,7 +26,7 @@ func ParseCommand(s *settings.Settings, raw string) ([]string, error) { command = append(command, cmd) command = append(command, args...) } else { - cmd, args, err := SplitCommandAndArgs(s.Shell[0]) + cmd, args, err := SplitCommandAndArgs(s.Shell) if err != nil { return nil, err } diff --git a/settings/settings.go b/settings/settings.go index 22908396..e2eb25df 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -25,7 +25,7 @@ type Settings struct { Branding Branding `json:"branding"` Tus Tus `json:"tus"` Commands map[string][]string `json:"commands"` - Shell []string `json:"shell"` + Shell string `json:"shell"` Rules []rules.Rule `json:"rules"` } diff --git a/settings/storage.go b/settings/storage.go index a006a84b..3199715a 100644 --- a/settings/storage.go +++ b/settings/storage.go @@ -72,8 +72,8 @@ func (s *Storage) Save(set *Settings) error { set.Rules = []rules.Rule{} } - if set.Shell == nil { - set.Shell = []string{} + if set.Shell == "" { + set.Shell = "" } if set.Commands == nil {