Skip to content

Commit f0e271b

Browse files
fix: correct neovim utils script path reference (#221)
* fix(scripts): correct neovim utils script path reference Change incorrect reference from 'neovim_utils.sh' to 'utils/neovim.sh'. The wrong path was causing chmod failures during remote neovim installation. Updates provider code and corresponding tests. * fix(provider): Pick up the correct binary release arch Signed-off-by: Amit Singh <amitds1997@gmail.com> * fix(scripts): Remove safe_subshell because it hides exit codes Signed-off-by: Amit Singh <amitds1997@gmail.com> * fix(provider): Fix building the install CMD to be run on remote Signed-off-by: Amit Singh <amitds1997@gmail.com> --------- Signed-off-by: Amit Singh <amitds1997@gmail.com> Co-authored-by: Amit Singh <amitds1997@gmail.com>
1 parent 4c5e8e3 commit f0e271b

File tree

10 files changed

+83
-50
lines changed

10 files changed

+83
-50
lines changed

lua/remote-nvim/providers/provider.lua

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function Provider:_setup_workspace_variables()
163163
})
164164
end
165165
self._remote_os = self._host_config.os
166-
self._remote_arch = self._host_config.arch
166+
self._remote_arch = utils.get_release_arch_name(self._host_config.arch)
167167

168168
if self._host_config.neovim_version == nil then
169169
local prompt_title
@@ -215,7 +215,7 @@ function Provider:_setup_workspace_variables()
215215
self._remote_neovim_download_script_path =
216216
utils.path_join(self._remote_is_windows, self._remote_scripts_path, "neovim_download.sh")
217217
self._remote_neovim_utils_script_path =
218-
utils.path_join(self._remote_is_windows, self._remote_scripts_path, "neovim_utils.sh")
218+
utils.path_join(self._remote_is_windows, self._remote_scripts_path, "utils/neovim.sh")
219219
self._remote_workspace_id_path =
220220
utils.path_join(self._remote_is_windows, self._remote_workspaces_path, self._remote_workspace_id)
221221

@@ -587,17 +587,42 @@ function Provider:_setup_remote()
587587
)
588588
end
589589

590-
-- Set correct permissions and install Neovim
591-
local install_neovim_cmd = ([[chmod +x %s && chmod +x %s && chmod +x %s && bash %s -v %s -d %s -m %s -a %s]]):format(
592-
self._remote_neovim_download_script_path,
593-
self._remote_neovim_utils_script_path,
594-
self._remote_neovim_install_script_path,
590+
local default_script_dir = vim.fn.fnamemodify(remote_nvim.default_opts.neovim_install_script_path, ":h:p")
591+
if not default_script_dir:match("/$") then
592+
default_script_dir = default_script_dir .. "/"
593+
end
594+
-- We list all paths in our scripts since we want to `chmod +x` all of them
595+
local all_scripts = vim.fs.find(function(name, _)
596+
return name:match("%.sh$")
597+
end, {
598+
limit = math.huge,
599+
type = "file",
600+
path = default_script_dir,
601+
})
602+
local paths_to_chmod = {}
603+
for _, path in ipairs(all_scripts) do
604+
local filepath = vim.fn.fnamemodify(path, ":p")
605+
local relative_path = filepath:gsub("^" .. vim.pesc(default_script_dir), "")
606+
local remote_script_path = utils.path_join(utils.is_windows, self._remote_scripts_path, relative_path)
607+
table.insert(paths_to_chmod, remote_script_path)
608+
end
609+
610+
local install_cmd_lst = {}
611+
for _, script_path in ipairs(paths_to_chmod) do
612+
table.insert(install_cmd_lst, "chmod +x " .. script_path)
613+
end
614+
615+
local install_cmd = ("bash %s -v %s -d %s -m %s -a %s"):format(
595616
self._remote_neovim_install_script_path,
596617
self._remote_neovim_version,
597618
self._remote_neovim_home,
598619
self._remote_neovim_install_method,
599620
self._remote_arch
600621
)
622+
table.insert(install_cmd_lst, install_cmd)
623+
624+
-- Set correct permissions and install Neovim
625+
local install_neovim_cmd = table.concat(install_cmd_lst, " && ")
601626

602627
if self.offline_mode and self._remote_neovim_install_method ~= "system" then
603628
-- We need to ensure that we download Neovim version locally and then push it to the remote

lua/remote-nvim/providers/utils.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function M.is_binary_release_available(kernel_name, arch)
175175
return true
176176
end
177177

178-
local unsupported_archs = { "arm", "risc", "aarch" }
178+
local unsupported_archs = { "risc" }
179179

180180
-- Neovim currently does not provide binaries for ARM or RISC
181181
return (

lua/remote-nvim/utils.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,18 @@ function M.run_cmd(cmd, args, cb)
271271
return job
272272
end
273273

274+
function M.get_release_arch_name(arch)
275+
arch = arch:lower()
276+
277+
if arch:match("x86_64") or arch:match("amd64") then
278+
return "x86_64"
279+
end
280+
281+
if arch:match("aarch64") or arch:match("arm64") then
282+
return "arm64"
283+
end
284+
285+
return arch
286+
end
287+
274288
return M

scripts/neovim_download.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ function download_neovim() {
3333
local checksum_path
3434
local expected_checksum
3535
local actual_checksum
36-
download_url=$(safe_subshell build_github_uri "$version" "$os" "$arch_type")
36+
download_url=$(build_github_uri "$version" "$os" "$arch_type")
3737
download_path="$download_dir/$(basename "$download_url")"
3838

3939
checksum_path="$download_path".sha256sum
4040
actual_checksum="$expected_checksum-actual" # This ensures that they do not match
41-
expected_checksum=$(safe_subshell get_sha256 "$version" "$os" "$arch_type")
41+
expected_checksum=$(get_sha256 "$version" "$os" "$arch_type")
4242

4343
if [ -e "$download_path" ] && [ -e "$checksum_path" ]; then
4444
expected_checksum=$(<"$checksum_path")

scripts/neovim_install.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function setup_neovim_linux_appimage() {
105105

106106
local nvim_release_name
107107
local download_url
108-
download_url=$(safe_subshell build_github_uri "$version" "Linux" "$arch_type")
108+
download_url=$(build_github_uri "$version" "Linux" "$arch_type")
109109
nvim_release_name=$(basename "$download_url")
110110
local nvim_appimage_temp_path="$temp_dir/$nvim_release_name"
111111

@@ -132,7 +132,7 @@ function setup_neovim_macos() {
132132

133133
local nvim_release_name
134134
local download_url
135-
download_url=$(safe_subshell build_github_uri "$version" "Darwin" "$arch_type")
135+
download_url=$(build_github_uri "$version" "Darwin" "$arch_type")
136136
nvim_release_name=$(basename "$download_url")
137137

138138
local extract_dir="${nvim_release_name%.tar.gz}"
@@ -189,9 +189,9 @@ function install_neovim() {
189189

190190
# Install Neovim based on the detected OS
191191
if [[ $os == "Linux" ]]; then
192-
safe_subshell setup_neovim_linux_appimage "$nvim_version" "$arch_type"
192+
setup_neovim_linux_appimage "$nvim_version" "$arch_type"
193193
elif [[ $os == "Darwin" ]]; then
194-
safe_subshell setup_neovim_macos "$nvim_version" "$arch_type"
194+
setup_neovim_macos "$nvim_version" "$arch_type"
195195
else
196196
echo "Unsupported operating system: $(uname)"
197197
exit 1
@@ -202,11 +202,11 @@ function install_neovim() {
202202
else
203203
"$download_neovim_script" -o "$os" -v "$nvim_version" -d "$nvim_version_dir" -t "source" -a "$arch_type"
204204
fi
205-
safe_subshell build_from_source "$nvim_version"
205+
build_from_source "$nvim_version"
206206
# Handle tar file downloaded or copied over
207207
elif [[ $install_method == "system" ]]; then
208208
# Handle symlinking to the system binary version
209-
safe_subshell link_to_system_neovim
209+
link_to_system_neovim
210210
else
211211
error "Unsupported Neovim installation method. Available installation methods are: binary, source or system"
212212
exit 1
@@ -265,4 +265,4 @@ if [[ $install_method == "system" && $nvim_version != "system" ]]; then
265265
fi
266266

267267
cd "$temp_dir" || exit 1
268-
safe_subshell install_neovim
268+
install_neovim

scripts/utils/api.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ function _get_available_downloader {
1717
function download_file {
1818
local URL="$1" OUTPUT_FILE="$2"
1919
if command -v curl &>/dev/null; then
20-
safe_subshell curl -fsSL -o "$OUTPUT_FILE" "$URL"
20+
curl -fsSL -o "$OUTPUT_FILE" "$URL"
2121
debug "Downloaded file from $URL to $OUTPUT_FILE using cURL"
2222
elif command -v wget &>/dev/null; then
23-
safe_subshell wget --quiet --output-document="$OUTPUT_FILE" "$URL"
23+
wget --quiet --output-document="$OUTPUT_FILE" "$URL"
2424
debug "Downloaded file from $URL to $OUTPUT_FILE using wget"
2525
else
2626
fatal --status=3 "No downloader found. Current options are cURL and wget"
@@ -37,15 +37,15 @@ function run_api_call {
3737
local URL="$1"
3838

3939
local downloader
40-
downloader=$(safe_subshell _get_available_downloader)
40+
downloader=$(_get_available_downloader)
4141
if [[ $downloader == "none" ]]; then
4242
fatal --status=3 "No downloader found. Available options are cURL and wget"
4343
fi
4444

4545
local tmpfile
46-
tmpfile="$(safe_subshell mktemp)"
46+
tmpfile="$(mktemp)"
4747

48-
safe_subshell download_file "$URL" "$tmpfile"
48+
download_file "$URL" "$tmpfile"
4949
local response
5050
response=$(<"$tmpfile")
5151
rm -f "$tmpfile"

scripts/utils/core.sh

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function _print_stack_trace {
4545
local i=0
4646
local line_no function_name file_name
4747
local msg=""
48-
local skip_functions=("fatal" "_print_stack_trace" "safe_subshell")
48+
local skip_functions=("fatal" "_print_stack_trace")
4949

5050
msg+="\nStack Trace (most recent call first):"
5151

@@ -184,13 +184,3 @@ function fatal {
184184

185185
exit "$STATUS"
186186
}
187-
188-
function safe_subshell {
189-
local output
190-
if ! output=$("$@"); then
191-
local status=$?
192-
fatal --status="$status" "Command '$*' failed with exit code $status"
193-
fi
194-
195-
echo "$output"
196-
}

scripts/utils/neovim.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ function _get_asset_name {
7878

7979
local asset_name
8080
if [[ $os == "Linux" ]]; then
81-
asset_name=$(safe_subshell _linux_asset_name "$version" "$arch_type")
81+
asset_name=$(_linux_asset_name "$version" "$arch_type")
8282
elif [[ $os == "Darwin" ]]; then
83-
asset_name=$(safe_subshell _macos_asset_name "$version" "$arch_type")
83+
asset_name=$(_macos_asset_name "$version" "$arch_type")
8484
else
8585
fatal --status=3 "Unsupported OS: $os"
8686
fi
@@ -96,18 +96,18 @@ function build_github_uri {
9696
local BASE_GITHUB_URI_PATH="https://github.com/neovim/neovim/releases/download/${VERSION}"
9797

9898
local ASSET_NAME
99-
ASSET_NAME=$(safe_subshell _get_asset_name "$VERSION" "$OS" "$ARCH_TYPE")
99+
ASSET_NAME=$(_get_asset_name "$VERSION" "$OS" "$ARCH_TYPE")
100100

101101
echo "${BASE_GITHUB_URI_PATH}/${ASSET_NAME}"
102102
}
103103

104104
function _find_sha256_for_version {
105105
local url="$1"
106106
local release_json
107-
release_json=$(safe_subshell cat)
107+
release_json=$(cat)
108108
local digest
109109

110-
digest=$(safe_subshell printf '%s' "$release_json" | tr -d '\n' | tr '{}' '\n' | grep "\"browser_download_url\"[[:space:]]*:[[:space:]]*\"$url\"" | grep -o 'digest"[[:space:]]*:[[:space:]]*"[^"]*' | grep -o '[^"]*$' | awk -F'sha256:' '{print $2}')
110+
digest=$(printf '%s' "$release_json" | tr -d '\n' | tr '{}' '\n' | grep "\"browser_download_url\"[[:space:]]*:[[:space:]]*\"$url\"" | grep -o 'digest"[[:space:]]*:[[:space:]]*"[^"]*' | grep -o '[^"]*$' | awk -F'sha256:' '{print $2}')
111111

112112
if [ -n "$digest" ]; then
113113
debug "SHA256 digest found for $url: $digest"
@@ -122,7 +122,7 @@ function get_sha256 {
122122
local VERSION=$1 OS=$2 ARCH_TYPE=$3
123123

124124
local DOWNLOAD_URI
125-
DOWNLOAD_URI=$(safe_subshell build_github_uri "$VERSION" "$OS" "$ARCH_TYPE")
125+
DOWNLOAD_URI=$(build_github_uri "$VERSION" "$OS" "$ARCH_TYPE")
126126

127127
local is_lesser
128128
is_lesser_version "$VERSION" v0.11.3
@@ -134,20 +134,20 @@ function get_sha256 {
134134
info "Neovim version $VERSION is less than 0.11.3, using legacy checksum file"
135135

136136
SHA256_URI="${DOWNLOAD_URI}.sha256sum"
137-
SHA256_SUM=$(safe_subshell run_api_call "$SHA256_URI")
137+
SHA256_SUM=$(run_api_call "$SHA256_URI")
138138

139-
SHA256_SUM=$(safe_subshell printf '%s\n' "$SHA256_SUM" | awk '{print $1}')
139+
SHA256_SUM=$(printf '%s\n' "$SHA256_SUM" | awk '{print $1}')
140140
else
141141
info "Neovim version $VERSION is greater than or equal to 0.11.3, using GitHub's checksum API"
142142

143143
SHA256_URI="https://api.github.com/repos/neovim/neovim/releases/tags/${VERSION}"
144144
debug "Downloading SHA256 from $SHA256_URI"
145145

146146
local response
147-
response=$(safe_subshell run_api_call "$SHA256_URI")
147+
response=$(run_api_call "$SHA256_URI")
148148
debug "Response from GitHub API: $response"
149149

150-
SHA256_SUM=$(safe_subshell printf '%s\n' "$response" | _find_sha256_for_version "$DOWNLOAD_URI")
150+
SHA256_SUM=$(printf '%s\n' "$response" | _find_sha256_for_version "$DOWNLOAD_URI")
151151
fi
152152

153153
if [[ -z $SHA256_SUM ]]; then

tests/remote-nvim/providers/provider_spec.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ describe("Provider", function()
171171
assert.equals(("%s/scripts"):format(remote_home), provider._remote_scripts_path)
172172
assert.equals(("%s/scripts/neovim_install.sh"):format(remote_home), provider._remote_neovim_install_script_path)
173173
assert.equals(("%s/scripts/neovim_download.sh"):format(remote_home), provider._remote_neovim_download_script_path)
174-
assert.equals(("%s/scripts/neovim_utils.sh"):format(remote_home), provider._remote_neovim_utils_script_path)
174+
assert.equals(("%s/scripts/utils/neovim.sh"):format(remote_home), provider._remote_neovim_utils_script_path)
175175
assert.equals(("%s/workspaces/%s"):format(remote_home, workspace_id), provider._remote_workspace_id_path)
176176

177177
-- XDG variables
@@ -636,7 +636,7 @@ describe("Provider", function()
636636
-- install neovim if needed
637637
assert.stub(run_command_stub).was.called_with(
638638
match.is_ref(provider),
639-
"chmod +x ~/.remote-nvim/scripts/neovim_download.sh && chmod +x ~/.remote-nvim/scripts/neovim_utils.sh && chmod +x ~/.remote-nvim/scripts/neovim_install.sh && bash ~/.remote-nvim/scripts/neovim_install.sh -v stable -d ~/.remote-nvim -m binary -a x86_64",
639+
"chmod +x ~/.remote-nvim/scripts/neovim_download.sh && chmod +x ~/.remote-nvim/scripts/neovim_install.sh && chmod +x ~/.remote-nvim/scripts/utils/api.sh && chmod +x ~/.remote-nvim/scripts/utils/core.sh && chmod +x ~/.remote-nvim/scripts/utils/neovim.sh && bash ~/.remote-nvim/scripts/neovim_install.sh -v stable -d ~/.remote-nvim -m binary -a x86_64",
640640
match.is_string()
641641
)
642642

@@ -695,7 +695,7 @@ describe("Provider", function()
695695

696696
assert.stub(run_command_stub).was.called_with(
697697
match.is_ref(provider),
698-
"chmod +x ~/.remote-nvim/scripts/neovim_download.sh && chmod +x ~/.remote-nvim/scripts/neovim_utils.sh && chmod +x ~/.remote-nvim/scripts/neovim_install.sh && bash ~/.remote-nvim/scripts/neovim_install.sh -v stable -d ~/.remote-nvim -m binary -a x86_64 -o",
698+
"chmod +x ~/.remote-nvim/scripts/neovim_download.sh && chmod +x ~/.remote-nvim/scripts/neovim_install.sh && chmod +x ~/.remote-nvim/scripts/utils/api.sh && chmod +x ~/.remote-nvim/scripts/utils/core.sh && chmod +x ~/.remote-nvim/scripts/utils/neovim.sh && bash ~/.remote-nvim/scripts/neovim_install.sh -v stable -d ~/.remote-nvim -m binary -a x86_64 -o",
699699
match.is_string()
700700
)
701701
end)
@@ -719,7 +719,7 @@ describe("Provider", function()
719719

720720
assert.stub(run_command_stub).was.called_with(
721721
match.is_ref(provider),
722-
"chmod +x ~/.remote-nvim/scripts/neovim_download.sh && chmod +x ~/.remote-nvim/scripts/neovim_utils.sh && chmod +x ~/.remote-nvim/scripts/neovim_install.sh && bash ~/.remote-nvim/scripts/neovim_install.sh -v stable -d ~/.remote-nvim -m binary -a x86_64 -o",
722+
"chmod +x ~/.remote-nvim/scripts/neovim_download.sh && chmod +x ~/.remote-nvim/scripts/neovim_install.sh && chmod +x ~/.remote-nvim/scripts/utils/api.sh && chmod +x ~/.remote-nvim/scripts/utils/core.sh && chmod +x ~/.remote-nvim/scripts/utils/neovim.sh && bash ~/.remote-nvim/scripts/neovim_install.sh -v stable -d ~/.remote-nvim -m binary -a x86_64 -o",
723723
match.is_string()
724724
)
725725
end)

tests/remote-nvim/providers/utils_spec.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,14 @@ describe("Binary release is available for", function()
126126
assert.is_true(utils.is_binary_release_available("Windows", "anything_goes"))
127127
end)
128128

129-
it("Linux but not for RISC and ARM", function()
129+
it("Linux for x86 and ARM", function()
130130
assert.is_true(utils.is_binary_release_available("Linux", "x86_64"))
131-
assert.is_false(utils.is_binary_release_available("Linux", "arm64"))
132-
assert.is_false(utils.is_binary_release_available("Linux", "armv7l"))
131+
assert.is_true(utils.is_binary_release_available("Linux", "arm64"))
132+
assert.is_true(utils.is_binary_release_available("Linux", "aarch64"))
133+
assert.is_true(utils.is_binary_release_available("Linux", "armv7l"))
134+
end)
135+
136+
it("Linux but not for RISC", function()
133137
assert.is_false(utils.is_binary_release_available("Linux", "riscv64"))
134138
end)
135139
end)

0 commit comments

Comments
 (0)