Alexey-T / CudaText

Cross-platform text editor, written in Free Pascal
Mozilla Public License 2.0
2.54k stars 173 forks source link

Cannot save file (EWriteError error) when owner is root, but owner of folder is user #5169

Closed timur-g closed 1 year ago

timur-g commented 1 year ago

Not sure if this is possible in some way, coud not find. If a user has no permisison, it would be handy if file could be open, edited and saved in superuser mode. I have 2 examples: Notepad++ has plugin NppSaveAsAdmin (obviously in Windows), DoubleCommander (wonderful file manager, from another Alex) has Admin rights in Windows and Linux ("you need to provide admin permission to create/delete this object").

Alexey-T commented 1 year ago

Wiki tells that Cud can save modified files even to folders w/o permissions. https://wiki.freepascal.org/CudaText#Can_app_save_files_to_system_directories.3F For example, open some file from write-protected folder on Unix/Linux. CudaText detects file permissions, so it should open file in read-only mode. Then, from "Command Palette", call "toggle read-only mode". Then you can edit the file. Edit it and save it - CudaText will try to save it via "pkexec".

timur-g commented 1 year ago

That does not fully work, tested in Mint 21 which is Ubuntu 22.04.. For files that have no permission for user to read, I see Cannot open file- permisison denied. If there is read permission I can open the file and write, but I cannot save: EWriteError, Cannot save file: I do not see how "toggle read-only mode" helps, seems like the opposite of what I wanted, does not seem to help to write file when user should submit superuser credentials. DoubleCmd approach seems OK to me.

Alexey-T commented 1 year ago

do you have program '/bin/cp' and '/usr/bin/pkexec'? if not, run

which pkexec

what does it show?

i made a test. copied my file fold-issue.json to /usr/src/ and removed 'w' permissions from it. i got OK result in Cud. it can edit file and save it:

Screenshot_2023-07-27_15-10-09

Alexey-T commented 1 year ago

For files that have no permission for user to read, I see Cannot open file- permisison denied.

yes, in this case Cud don't work.

If there is read permission I can open the file and write, but I cannot save: EWriteError, Cannot save file:

what is full file path? what ls -l does show for file?

timur-g commented 1 year ago

I see /bin/cp' and 'which pkexec' gives: /usr/bin/pkexec File I tested is: -rw-r--r-- 1 root root 0 How to get that dialog, is it some plugin?

Alexey-T commented 1 year ago

How to get that dialog, is it some plugin?

it is build-in dialog of 'pkexec' (which is run by Cud when saving file).

i cannot repeat the problem with -rw-r--r-- 1 root root 0. what is full file path? what is ls -l of parent dir?

timur-g commented 1 year ago

I confirm what you wrote and got that dialog in other folder with the same permissions 644 but other parent permission.

Imagine that 1st time I tried I got this error :) Here is this folder, it is somewhat artificial as I just wanted to test, but still possible. drwxrwxr-x 4 user user 4,0K Jul 27 15:39 . drwxr-x--- 57 user user 4,0K Jul 27 15:51 .. -rw-r--r-- 1 root root 11 Jul 27 14:47 root.txt

With that save dialog, could you convert this issue to get the same dialog on fileopen, if there are no sufficient permisisons for that?

Alexey-T commented 1 year ago
drwxr-x--- 57 user user 4,0K Jul 27 15:51 ..
-rw-r--r-- 1 root root 11 Jul 27 14:47 root.txt

with this, I got the error EWriteError: cannot save file. will study this case.

Alexey-T commented 1 year ago

i made a fix! let's test 1 of 2 binaries: linux x64 gtk2 / qt5.

builds.zip

timur-g commented 1 year ago

Yes, working now, thanks. One issue per ticket and this one may be closed. But please comment if I should open the new one for the same dialog on fileopen, if there are no sufficient permisisons.

Alexey-T commented 1 year ago

issue for missing R permission? yes, open a new issue for that. I cannot solve it so easy, so it will stay for some time.