Skip to content

Commit

Permalink
Add config keys to set custom permission for files and folders
Browse files Browse the repository at this point in the history
Add config key to set the file creation permissions

Rename file_mode to new_file_mode

Add new_folder_mode to store the default folder creation mode

Remove doc about new_file_mode

Fix how the folder and file mode are added to config
  • Loading branch information
fortizc committed Dec 26, 2024
1 parent dba0375 commit d91e574
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions doc/oil.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ CONFIG *oil-confi
return nil
end,
},
-- Set the default mode to create files
new_files_mode = 644,
-- Set the default mode to create folders
new_folder_mode = 755,
-- Extra arguments to pass to SCP when moving/copying files over SSH
extra_scp_args = {},
-- EXPERIMENTAL support for performing file operations with git
Expand Down
4 changes: 2 additions & 2 deletions lua/oil/adapters/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ M.perform_action = function(action, cb)
end

if action.entry_type == "directory" then
uv.fs_mkdir(path, 493, function(err)
uv.fs_mkdir(path, config.new_folder_mode, function(err)
-- Ignore if the directory already exists
if not err or err:match("^EEXIST:") then
cb()
Expand All @@ -550,7 +550,7 @@ M.perform_action = function(action, cb)
---@diagnostic disable-next-line: param-type-mismatch
uv.fs_symlink(target, path, flags, cb)
else
fs.touch(path, cb)
fs.touch(path, config.new_file_mode, cb)
end
elseif action.type == "delete" then
local _, path = util.parse_url(action.url)
Expand Down
2 changes: 1 addition & 1 deletion lua/oil/adapters/trash/mac.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ M.perform_action = function(action, cb)
---@diagnostic disable-next-line: param-type-mismatch
uv.fs_symlink(target, path, flags, cb)
else
fs.touch(path, cb)
fs.touch(path, config.new_file_mode, cb)
end
elseif action.type == "delete" then
local _, path = util.parse_url(action.url)
Expand Down
11 changes: 11 additions & 0 deletions lua/oil/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ local default_config = {
return nil
end,
},
-- Set the default mode to create files
new_file_mode = 644,
-- Set the default mode to create folders
new_folder_mode = 755,
-- Extra arguments to pass to SCP when moving/copying files over SSH
extra_scp_args = {},
-- EXPERIMENTAL support for performing file operations with git
Expand Down Expand Up @@ -232,6 +236,8 @@ default_config.view_options.highlight_filename = nil
---@field keymaps table<string, any>
---@field use_default_keymaps boolean
---@field view_options oil.ViewOptions
---@field new_file_mode integer
---@field new_folder_mode integer
---@field extra_scp_args string[]
---@field git oil.GitOptions
---@field float oil.FloatWindowConfig
Expand Down Expand Up @@ -260,6 +266,8 @@ local M = {}
---@field keymaps? table<string, any>
---@field use_default_keymaps? boolean Set to false to disable all of the above keymaps
---@field view_options? oil.SetupViewOptions Configure which files are shown and how they are shown.
---@field new_file_mode? integer Set the default mode to create files
---@field new_folder_mode? integer Set the default mode to create folders
---@field extra_scp_args? string[] Extra arguments to pass to SCP when moving/copying files over SSH
---@field git? oil.SetupGitOptions EXPERIMENTAL support for performing file operations with git
---@field float? oil.SetupFloatWindowConfig Configuration for the floating window in oil.open_float
Expand Down Expand Up @@ -408,6 +416,9 @@ M.setup = function(opts)
if opts.preview and not opts.confirmation then
new_conf.confirmation = vim.tbl_deep_extend("keep", opts.preview, default_config.confirmation)
end

new_conf.new_file_mode = tonumber(tostring(new_conf.new_file_mode), 8)
new_conf.new_folder_mode = tonumber(tostring(new_conf.new_folder_mode), 8)
-- Backwards compatibility. We renamed the 'preview' config to 'preview_win'
if opts.preview and opts.preview.update_on_cursor_moved ~= nil then
new_conf.preview_win.update_on_cursor_moved = opts.preview.update_on_cursor_moved
Expand Down
6 changes: 3 additions & 3 deletions lua/oil/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ M.abspath = function(path)
end

---@param path string
---@param mode integer mode to open file (octal)
---@param cb fun(err: nil|string)
M.touch = function(path, cb)
uv.fs_open(path, "a", 420, function(err, fd) -- 0644
M.touch = function(path, mode, cb)
uv.fs_open(path, "a", mode, function(err, fd)
if err then
cb(err)
else
Expand Down Expand Up @@ -146,7 +147,6 @@ end
---@param dir string
---@param mode? integer
M.mkdirp = function(dir, mode)
mode = mode or 493
local mod = ""
local path = dir
while vim.fn.isdirectory(path) == 0 do
Expand Down

0 comments on commit d91e574

Please sign in to comment.