bulletmark / edir

Program to rename, remove, and copy files and directories using your editor
139 stars 8 forks source link

Handle missing permissions in a smart way #13

Closed hupfdule closed 2 years ago

hupfdule commented 2 years ago

The thing that bugs me the most in vidir is that changes that cannot be applied due to missing permissions are lost.

Missing permissions are common when trying to edit root-owned files, but forgetting to use sudo.

This is especially annoying if there were lots of manual changes that then have to be applied again.

I think there are two options to support a use case to handle these problems in a smarter way:

  1. Check for permissions to rename/delete/copy and if there are insufficient permissions, call sudo for applying the actual changes.
  2. Write the failed operations to a file that can later be fed to edir with the correct permissions (e.g. by calling sudo edir < the_special_file).

The advantages of the first option are (in my opinion):

The advantages of the second option are (in my opinion):

Due to the advantages descibed above I think option 2 is the better option.

If option 2 should be implemented the format of the file must be defined. In my opinion it should a very easy human and machine readable format. Here is an example that just springs to mind as a rough idea:

r /some/file  →  /some/FiLe
d /some/file
c /some/file  →  /some/copy

The first being a rename, the second a delete and the third a copy operation. Of course instead of the Unicode arrow an ASCII arrow (->) can be used to allow easier creation/modification of such files by the user. But it must be assured that there is no confusion between the separator char (the arrow surrounded by (maybe a specific amount of) spaces) and such a char sequence inside a file name. But that should be easily solvable by checking that the sequence occurs only once per file.

When generating the file from edir itself (due to an error when trying to apply the operation), a comment header could be added (like an interactive rebase in git) that describes the format:

# Each line must be of the following format:
# For "renaming":
# r <file>  →  <new name>
#
# For "deleting":
# d <file>
#
# For "copying":
# c <file> →  <new file>

Also, in such a case, it must be prominently displayed to the user

bulletmark commented 2 years ago

Sorry but the suggestion to automatically invoke sudo to overcome permission issues horrifies me as it would any other experienced Linux user. Quite simply, you are doing something fundamentally wrong if you are experiencing permission errors even occasionally.