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

Can't create a new file after first run as root #202

Closed
Janiczek opened this issue Aug 28, 2017 · 16 comments · Fixed by #951
Closed

Can't create a new file after first run as root #202

Janiczek opened this issue Aug 28, 2017 · 16 comments · Fixed by #951

Comments

@Janiczek
Copy link

Janiczek commented Aug 28, 2017

When I try to create a new file from the main window ("new file / open file / new from clipboard"), the app doesn't initialize the text editor window and starts looking like this (still responsive, but I can't write):

from_main_window

When I try to create a new file from an opened file (by clicking on the + sign in the tab list), similar story (but I can still edit the previously open file) - the plus sign stays "focused", but nothing else happens:

plus


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@Janiczek
Copy link
Author

I have built io.elementary.code from source and run it, logging ot STDOUT. It gave this error when clicking on the "New File" button:

[FATAL 22:43:59.172485] DocumentView.vala:120: Error opening file '/home/martin/.local/share/scratch-text-editor/unsaved/Text file from 2017-08-28 22:43:59': Permission denied

The directory structure has these permissions:

rwx------ ~
rwx------ ~/.local
rwx------ ~/.local/share
rwxr-xr-x ~/.local/share/scratch-text-editor
rwxr-xr-x ~/.local/share/scratch-text-editor/unsaved

(This is from clean elementary OS installation.)

When I added the write permissions (chmod 777) to scratch-text-editor and unsaved directories, it started working.

I don't understand the cause - maybe some installation script?

@matzipan
Copy link
Contributor

Does "clean" elementary OS install mean you did not copy the home directory from another installation?

@matzipan
Copy link
Contributor

Can you also do a ls -al /home/martin/.local/share? Perhaps first time when you ran Code it was run as root or something and the directory in there was created as root, which is why the permissions did not allow you to write to it.

@Janiczek
Copy link
Author

Correct, I have not copied the home directory from another installation. (Only post-installation I copied some data like photos etc., but no dotfiles / directories.)

martin@janiczek:~$ ls -al /home/martin/.local/share
total 176
drwxr-xr-x 25 martin martin  4096 srp 29 09:25 .
drwxr-xr-x  3 martin martin  4096 srp 25 01:37 ..
drwx------  2 martin martin  4096 srp 29 09:11 applications
drwx------  2 martin martin  4096 srp 25 09:28 desktop-directories
drwx------  4 martin martin  4096 srp 24 23:38 epiphany
drwx------  7 martin martin  4096 srp 25 01:37 evolution
drwxr-xr-x  2 martin martin  4096 srp 25 01:37 gnome-settings-daemon
-rw-rw-r--  1 martin martin   505 srp 25 10:14 gsettings-data-convert
drwx------  2 martin martin  4096 srp 29 09:11 gvfs-metadata
drwxrwxr-x  2 martin martin  4096 srp 25 14:41 icc
drwx------  3 martin martin  4096 srp 25 09:26 icons
drwxrwxr-x  3 martin martin  4096 srp 25 10:43 JetBrains
drwxr-xr-x  6 martin martin  4096 srp 25 11:42 keybase
drwx------  2 martin martin  4096 srp 29 09:38 keyrings
drwx------  2 martin martin  4096 srp 25 11:53 libgda
drwxrwxr-x  3 martin martin  4096 srp 25 14:16 messenger
drwxrwxr-x  2 martin martin  4096 srp 25 18:17 nasc
drwxrwxr-x  2 martin martin  4096 srp 25 11:53 noise
drwx------  5 martin martin  4096 srp 29 09:23 nvim
drwxrwxr-x  2 martin martin  4096 srp 25 13:43 pantheon-photos
drwxrwxr-x  3 martin martin  4096 srp 25 01:37 plank
-rw-------  1 martin martin 20480 srp 29 09:25 recently-used.xbel
-rw-rw-r--  1 martin martin 13357 srp 28 11:36 recently-used.xbel.KKUX5Y
-rw-rw-r--  1 martin martin  2356 srp 25 10:54 recently-used.xbel.WT5D5Y
drwxrwxrwx  3 root   root    4096 srp 24 23:40 scratch-text-editor
drwx------  2 martin martin  4096 srp 25 01:37 sounds
drwx------  5 martin martin  4096 srp 25 15:39 Trash
drwx------  3 martin martin  4096 srp 25 13:49 webkitgtk
drwx------  3 martin martin  4096 srp 25 01:37 zeitgeist

I have also started on 0.4.1 Loki but then added the daily and os-patches PPAs and upgraded everything, but this issue was present before that change.

@matzipan
Copy link
Contributor

Well, as you can see on the scratch-text-editor line, it says the folder is owned by root and belongs to the root group, which means when you first ran Code, you ran it as root (probably with sudo). So chmod 755 scratch-text-editor && sudo chown martin:martin scratch-text-editor should fix your issue.

@Janiczek
Copy link
Author

Is it a good idea to show some kind of message to the user? ("Can't open a new file, click this button to fix this - might want sudo permissions" or something similar)

@matzipan
Copy link
Contributor

It's a bug caused by an edge case. We definetely can't cover all posibilities. I consider that the error message "Permission denied" is descriptive enough.

@donadigo donadigo reopened this Aug 29, 2017
@donadigo
Copy link
Collaborator

If the saved file was saved as root, and it cannot be read by Scratch, it should just ignore it and create a new one. Also: even if Scratch is opened as root, the file should be saved with right permissions and not with root permissions.

@matzipan
Copy link
Contributor

Well I don't think it's because the file was saved as root, it's that the directory was created as root so you can't create a new file in there.

@Janiczek
Copy link
Author

Just want to add that the error Permission denied can't be seen anywhere in the app. With some developer effort the user can run the app from terminal and see it, but still...

@matzipan
Copy link
Contributor

You don't need to compile the app from scratch to run from the command line, just run io.elementary.code in the terminal.

@Janiczek
Copy link
Author

Yes, I didn't mean to say the user has to compile the app (although I did). But there still probably will be some developer guidance needed to tell the user to run the app in the terminal. (Seeing as the elementary OS targets non-tech-savvy people too, I think a hint in the app could help, although that's up for discussion.)

@matzipan
Copy link
Contributor

You're right, it should handle this more gracefully.

@danirabbit
Copy link
Member

danirabbit commented Aug 29, 2017

The proper solution is probably to completely disallow running with sudo as we’ve done in files and only allow running with pkexec so that this can’t happen again

@danirabbit danirabbit changed the title Can't create a new file (empty or from clipboard) Can't create a new file after first run as root Sep 5, 2017
@danirabbit
Copy link
Member

Relevant files commit here: elementary/files@f0e4a44

@linkert
Copy link

linkert commented Oct 24, 2018

The proper solution is probably to completely disallow running with sudo as we’ve done in files and only allow running with pkexec so that this can’t happen again

Sorry to quote reply such an old comment but I found it relevant as I filed issue #546. How do I modify locked files then if the proper solution is to have Code be unable to run under sudo all together? It's something that people do from time to time on Linux, BSD and macOS right? To me, as the end user I would much rather use Code over whipping out nano, nvim, ed or any other cli editor for editing locked files - for whatever reason I see fit to edit whichever file I want to edit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants