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

Adds support for BSD based Operating Systems #210

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

miversen33
Copy link
Owner

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

@miversen33
Copy link
Owner Author

This closes #209

@miversen33
Copy link
Owner Author

@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"

@miversen33 miversen33 self-assigned this Dec 4, 2024
@s-daveb
Copy link

s-daveb commented Dec 4, 2024

Screenshot 2024-12-04 at 10 46 35 AM

I'm getting the occasional glitch, but it's a marked improvement!
Give me a little bit to take some notes and capture log files.

@s-daveb
Copy link

s-daveb commented Dec 4, 2024

I found that the changes worked perfectly on my FreeBSD systems, but not on my macOS hosts. Luckily, I noticed that the macOS stat manpage contains:

HISTORY
     The stat utility appeared in NetBSD 1.6 and FreeBSD 4.10.

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 neotree remote, I noticed in the logs that it couldn't detect macOS because it has no /etc/release file.

I looked at your _get_os() method and tweaked it so that uses the uname command to detect the operating system. However, I left the call to /etc/release commented under the Linux branch of the method, so that Ubuntu, Redhat, and other OSes can be detected in the future.

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:

changes.patch

@miversen33
Copy link
Owner Author

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

@miversen33
Copy link
Owner Author

miversen33 commented Dec 5, 2024

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!

@miversen33
Copy link
Owner Author

@s-daveb have you had an opportunity to test this PR after my updates?

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.

2 participants