Skip to content

Commit d6c1ab0

Browse files
committed
Godot addon: Don't call chmod on Unix systems, use Godot built-in,
capture stderr Attempted fix for #286
1 parent cd96ed7 commit d6c1ab0

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

addons/GDQuest_GDScript_formatter/install_and_update.gd

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ enum HttpRequestState {
88
}
99

1010
const URL_GITHUB_API_LATEST_RELEASE = "https://api.github.com/repos/gdquest/GDScript-formatter/releases/latest"
11-
1211
signal installation_completed(binary_path: String)
1312
signal installation_failed(error_message: String)
1413

@@ -228,6 +227,20 @@ func _download_and_install_binary(zip_data: PackedByteArray, platform_info: Dict
228227
file.close()
229228

230229
if not OS.get_name().to_lower().contains("windows"):
231-
OS.execute("chmod", ["+x", binary_path])
230+
# This should be equivalent to setting the binary to permissions 755
231+
const UNIX_EXECUTABLE_PERMISSIONS = (
232+
FileAccess.UNIX_READ_OWNER
233+
| FileAccess.UNIX_WRITE_OWNER
234+
| FileAccess.UNIX_EXECUTE_OWNER
235+
| FileAccess.UNIX_READ_GROUP
236+
| FileAccess.UNIX_EXECUTE_GROUP
237+
| FileAccess.UNIX_READ_OTHER
238+
| FileAccess.UNIX_EXECUTE_OTHER
239+
)
240+
var permissions_error := FileAccess.set_unix_permissions(binary_path, UNIX_EXECUTABLE_PERMISSIONS)
241+
if permissions_error != OK:
242+
push_error("Failed to make formatter executable: ", binary_path)
243+
DirAccess.remove_absolute(binary_path)
244+
return ""
232245

233246
return binary_path

addons/GDQuest_GDScript_formatter/plugin.gd

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ func _enter_tree() -> void:
9090
installer.installation_completed.connect(
9191
func _on_installation_completed(binary_path: String) -> void:
9292
set_editor_setting(SETTING_FORMATTER_PATH, binary_path)
93-
_has_formatter_command = true
93+
_has_formatter_command = has_command(binary_path)
94+
if not _has_formatter_command:
95+
push_error("GDScript Formatter: Installed binary cannot be executed: " + binary_path)
96+
return
9497
add_format_command()
9598
add_lint_command()
9699
# After installing the formatter we can add the menu option to show the uninstall command
@@ -367,7 +370,7 @@ func has_command(command: String) -> bool:
367370
if command.is_empty():
368371
return false
369372
var output: Array = []
370-
var exit_code := OS.execute(command, ["--version"], output)
373+
var exit_code := OS.execute(command, ["--version"], output, true)
371374
return exit_code == OK
372375

373376

@@ -629,6 +632,7 @@ func format_code(script: GDScript, force_reorder := false, source_content: Varia
629632
get_editor_setting(SETTING_FORMATTER_PATH),
630633
formatter_arguments,
631634
output,
635+
true,
632636
)
633637

634638
var formatted_content := ""

0 commit comments

Comments
 (0)