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

fix: fs_access on dir to check if possible to write to the directory (#554) #555

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 2 additions & 34 deletions lua/oil/adapters/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -455,26 +455,6 @@ M.list = function(url, column_defs, cb)
end, 10000)
end

---@type nil|integer[]
local _group_ids
---@return integer[]
local function get_group_ids()
if not _group_ids then
local output = vim.fn.system({ "id", "-G" })
if vim.v.shell_error == 0 then
_group_ids = vim.tbl_map(tonumber, vim.split(output, "%s+", { trimempty = true }))
else
-- If the id command fails, fall back to just using the process group
_group_ids = { uv.getgid() }
vim.notify(
"[oil] missing the `id` command. Some directories may not be modifiable even if you have group access.",
vim.log.levels.WARN
)
end
end
return _group_ids
end

---@param bufnr integer
---@return boolean
M.is_modifiable = function(bufnr)
Expand All @@ -490,20 +470,8 @@ M.is_modifiable = function(bufnr)
return true
end

-- Can't do permissions checks on windows
if fs.is_windows then
return true
end

local uid = uv.getuid()
local rwx = stat.mode
if uid == stat.uid then
rwx = bit.bor(rwx, bit.rshift(stat.mode, 6))
end
if vim.tbl_contains(get_group_ids(), stat.gid) then
rwx = bit.bor(rwx, bit.rshift(stat.mode, 3))
end
return bit.band(rwx, 2) ~= 0
-- fs_access can return nil, force boolean return
return uv.fs_access(dir, "W") == true
end

---@param action oil.Action
Expand Down
Loading