Add config key to set the file creation permissions#537
Add config key to set the file creation permissions#537fortizc wants to merge 1 commit intostevearc:masterfrom
Conversation
| -- Set the default mode to create files (:help oil-file_creation) | ||
| create_files_mode = 420, |
There was a problem hiding this comment.
We don't expect most users to need to modify this, so let's move it down to below the view_options.
There was a problem hiding this comment.
If we're adding the ability to adjust the mode of the created files, we should do the same for directories. We could use two options for this new_file_mode and new_dir_mode.
There was a problem hiding this comment.
Since most people are used to thinking about file permissions in octal, the config option should be octal and we should automatically convert it.
| new_conf.confirmation = vim.tbl_deep_extend("keep", opts.preview, default_config.confirmation) | ||
| end | ||
|
|
||
| M.file_mode = opts.create_files_mode |
| -------------------------------------------------------------------------------- | ||
| FILE CREATION *oil-file_creation* | ||
|
|
||
|
|
||
| Oil defines `create_files_mode` to set the permission for new files. The mode | ||
| follows the Posix numeric standard which use octal notation (base-8), however | ||
| the variable must be set in decimal. | ||
|
|
||
| 00700 user (file owner) has read, write, and execute permission | ||
| 00400 user has read permission | ||
| 00200 user has write permission | ||
| 00100 user has execute permission | ||
| 00070 group has read, write, and execute permission | ||
| 00040 group has read permission | ||
| 00020 group has write permission | ||
| 00010 group has execute permission | ||
| 00007 others have read, write, and execute permission | ||
| 00004 others have read permission | ||
| 00002 others have write permission | ||
| 00001 others have execute permission | ||
| (from the open (2) man pages) | ||
|
|
||
| An easy way to provide the right value for `create_files_mode` is using | ||
| `tonumber(e [, base])` function with `base = 8`, for example: | ||
| >lua | ||
| create_files_mode = tonumber("0644", 8) | ||
|
|
||
| The default value is 420 in decimal or 0644 in octal | ||
|
|
||
|
|
There was a problem hiding this comment.
I actually don't think we need this section. It's explaining:
- what the octal file permissions mean
- how to convert octal to decimal
- the default value
Point 3 is already documented in the options section. Point 2 is obviated if we accept the permission in octal. And for point 1 I would argue that if you don't know what octal file permissions are, you probably shouldn't be changing this config value and I don't think the oil docs are the correct place to be learning about them.
e96ca6f to
d91e574
Compare
| -- Set the default mode to create files | ||
| new_files_mode = 644, | ||
| -- Set the default mode to create folders | ||
| new_folder_mode = 755, |
There was a problem hiding this comment.
I am fully aware of how this sounds, and I'm really sorry to be this pedantic, but "folder" is Windows terminology. Typically in Unix contexts we would refer to these as "directories". Elsewhere in this plugin we always refer to these as directories. For consistency sake, could we rename this to new_dir_mode?
d91e574 to
17ae7b0
Compare
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 Rename new_folder_mode to new_dir_mode
17ae7b0 to
e7363e4
Compare
|
Hey, all changes are done, so it's ready if you want to review it again. Thanks! |
stevearc
left a comment
There was a problem hiding this comment.
The previous comment about mkdirp has not been addressed, and new bugs were introduced in that function
| mode = mode or 493 | ||
| local mod = "" | ||
| local path = dir | ||
| local mod = mode |
There was a problem hiding this comment.
What is going on here? This change looks completely wrong
Problem: files were always created with mode 0644 and directories with 0755, hardcoded in fs.touch and uv.fs_mkdir. Users who need different defaults (e.g. 0600 for security) had no config option. Solution: add new_file_mode (default 420 = 0644) and new_dir_mode (default 493 = 0755) config options, passed through to fs.touch and uv.fs_mkdir in the files and mac trash adapters. The fs.touch signature accepts an optional mode parameter with backwards compatibility (detects function argument to support old callers). Local cache directories (SSH, S3) continue using standard system permissions rather than the user-configured mode. Based on: stevearc#537
Problem: files were always created with mode 0644 and directories with 0755, hardcoded in fs.touch and uv.fs_mkdir. Users who need different defaults (e.g. 0600 for security) had no config option. Solution: add new_file_mode (default 420 = 0644) and new_dir_mode (default 493 = 0755) config options, passed through to fs.touch and uv.fs_mkdir in the files and mac trash adapters. The fs.touch signature accepts an optional mode parameter with backwards compatibility (detects function argument to support old callers). Local cache directories (SSH, S3) continue using standard system permissions rather than the user-configured mode. Based on: stevearc#537
This PR defines a new config key called
create_files_modeto set the default permission used when a file is created.Currently, Oil uses 644 (420 in decimal) but, at least on Linux most of the tools like (n)vim, touch, or even a simple
> filenameby default uses 664 (436 decimal) so, with this option the user is able to set the default value.