-
Notifications
You must be signed in to change notification settings - Fork 3
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
Adds support for BSD based Operating Systems #210
base: main
Are you sure you want to change the base?
Conversation
This closes #209 |
@s-daveb can you try out 209-stat-non-linux-hosts for me? You are my guinea pig for this. I have tested against my current systems and it seems fine so I believe we are not breaking anything existing with this PR. I am not super fond of how I did a few things on this PR so I may need to clean it up a bit, but first I want to ensure it solves the main issue that is "No BSD Support" |
I found that the changes worked perfectly on my FreeBSD systems, but not on my macOS hosts. Luckily, I noticed that the macOS
I tried a few of your BSD-style stat calls in my macOS terminal and it worked. I made this change: function SSH:_get_stat_flags()
--[[ Removed check for GNU stat, using the --version flag.
BSD and macOS `stat` does not support long-style `--` flags and
errors out. Besides, self.os contains accurate OS information.
--]]
if self.os:match('BSD') or self.os:match('macos') then
self.stat_flags = SSH.CONSTANTS.STAT_COMMAND_FLAGS.FREEBSD
self.find_flags = SSH.CONSTANTS.FIND_COMMAND_FLAGS.FREEBSD
else
self.stat_flags = SSH.CONSTANTS.STAT_COMMAND_FLAGS.LINUX
self.find_flags = SSH.CONSTANTS.FIND_COMMAND_FLAGS.LINUX
end But when I tried I looked at your function SSH:_get_os()
local result = "Unknown"
local _get_os_command = "uname" -- Portable (POSIX) way to get the OS
local output = self:run_command(_get_os_command, {
[command_flags.STDOUT_JOIN] = '',
[command_flags.STDERR_JOIN] = ''
})
if output.exit_code ~= 0 or not output.stdout or output.stdout == "" then
-- Workaround to detect Windows:
-- Check if the path separator is backslash
if package.config:sub(1, 1) == "\\" then
result = "windows"
end
else
result = output.stdout:gsub("%s+", "") -- Trim whitespace
if result == "Linux" then
result = "linux"
-- Get Distribution
-- local _get_os_command = 'cat /etc/*release* | grep -E "^NAME=" | cut -d "=" -f 2 | tr -d \'"\''
-- local output = self:run_command(_get_os_command, {
-- [command_flags.STDOUT_JOIN] = '',
-- [command_flags.STDERR_JOIN] = ''
-- })
-- if output.exit_code -= 0 and output.stdout and output.stdout ~= "" then
-- result = output.stdout:gsub("%s+", "") -- Remove any surrounding whitespace
-- end
elseif result == "Darwin" then
result = "macos"
elseif result:find("BSD") then
result = result:match("%w+BSD") or "Unknown"
end
end
return result
end After making these changes, it works for my macOS hosts as well. 🎉 Thanks for working on this. I'm not sure how to contribute to this PR, as I don't have the gh commandline. Here is the git diff of the changes: |
Since this is on a PR, I'll have to make the changes. I'll pull the patch in, do some more testing this afternoon and hopefully see if merged to main tonight/tomorrow :) Thanks for your help! Once I've pulled your patch in, I'll have you test once more to ensure it's working as expected for you, before I merge |
Alright, I have cleaned up a few things and merged your patch. @s-daveb can you pull it and ensure its still operating as expected for you? I appreciate you submitting that btw! |
@s-daveb have you had an opportunity to test this PR after my updates? |
This adds support for navigating (and manipulating) BSD based operating systems. In addition, it extends stat and find to allow for easily adding future support for other operating systems should we need that