Bug 363176 - Enabling the script console crashes amarok
Summary: Enabling the script console crashes amarok
Status: RESOLVED FIXED
Alias: None
Product: amarok
Classification: Applications
Component: Tools/Script Manager (other bugs)
Version First Reported In: 2.8.90 (2.9 beta)
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: 2.9
Assignee: Amarok Bugs
URL: https://bugs.gentoo.org/show_bug.cgi?...
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-17 11:15 UTC by Markus Wernig
Modified: 2016-05-18 20:05 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 2.9
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Wernig 2016-05-17 11:15:16 UTC
When the script console is enabled (Settings -> Configure Amarok -> Scripts, there's a checkbox on the bottom of the window) and the Apply or OK button clicked, an error popup appears with the error:

"The document could not be saved, as it was not possible to write to /usr/share/apps/amarok/scriptconsole//Script-NNNNNNNN/main.js.
Check that you have write access to this file or that enough disk space is available." (NNNNNNNN being a random number that changes each time)

After closing the error message, amarok aborts silently.
On each subsequent start, the error message reappears, and closing it terminates amarok immediately, so there is no way even to disable the script console again.

The only way is to disable it in the config file ~/.kde/share/config/amarokrc in the [ScriptManager] section, set EnableScriptConsole=false.

Reproducible: Always

Steps to Reproduce:
1. Open Settings -> Configure Amarok -> Scripts
2. Enable checkbox with label "Enable script console" on bottom of window
3. Click apply

Actual Results:  
Error message pops up, amarok crashes and keeps crashing on subsequent restart attempts



Actually it seems as if the checkbox that leads to this is not really needed, as enabling the "Script Console" entry in the list on the same window opens the console without problems.
Comment 1 Markus Wernig 2016-05-17 11:16:12 UTC
This was reported downstream at https://bugs.gentoo.org/show_bug.cgi?id=583016
Comment 2 Myriam Schweingruber 2016-05-17 13:53:10 UTC
Did you make sure the folder is writeable and tried again? Strangely the folder this tries to write to is in /usr/.. , while it should be in your home folder at ~/.kde/.. , so there is something wrong in your installation.
FWIW: I can't reproduce this here with current git master, which should be very similar to 2.8.90
Comment 3 Markus Wernig 2016-05-17 15:45:10 UTC
(In reply to Myriam Schweingruber from comment #2)
> Did you make sure the folder is writeable and tried again?
After chmod 777 /usr/share/apps/amarok/scriptconsole the error does not occur anymore.
But obviously there is absolutely no reason why amarok should be writing something there.
What are the permissions of  /usr/share/apps/amarok/scriptconsole on your system?

> Strangely the
> folder this tries to write to is in /usr/.. , while it should be in your
> home folder at ~/.kde/.. , so there is something wrong in your installation.
Maybe so. Do you see any chance to find out what that is? There is no directory called "scriptconsole" in ~/.kde4/share/apps/amarok ... oh wait! 
After I created the directory ~/.kde4/share/apps/amarok/scriptconsole by hand, amarok does not crash anymore, but in fact the script console opens ... so it's a missing directory :-)

But that would still be a bug, right? It shouldn't really crash, but just create the directory.
Comment 4 Myriam Schweingruber 2016-05-18 16:46:12 UTC
(In reply to Markus Wernig from comment #3)
> (In reply to Myriam Schweingruber from comment #2)
...
> > Strangely the
> > folder this tries to write to is in /usr/.. , while it should be in your
> > home folder at ~/.kde/.. , so there is something wrong in your installation.
> Maybe so. Do you see any chance to find out what that is? There is no
> directory called "scriptconsole" in ~/.kde4/share/apps/amarok ... oh wait! 
> After I created the directory ~/.kde4/share/apps/amarok/scriptconsole by
> hand, amarok does not crash anymore, but in fact the script console opens
> ... so it's a missing directory :-)
> 
> But that would still be a bug, right? It shouldn't really crash, but just
> create the directory.
Well, as I said, that directory is created correctly in ~/.kde/share/apps/amarok/.. in current git master. So either this has been fixed since 2.8.90 (which I am sure there was no commit about this), or there is something wrong in your installation, trying to install in /usr/.. instead of the home directory. Not sure there is a bug in Amarok, but I will have a look at the code
Comment 5 Johannes Huber 2016-05-18 17:27:29 UTC
ScriptConsole.cpp: 
>   if( m_savePath.isEmpty() )
 >      m_savePath = KUrl( KStandardDirs::locate( "data", "amarok/scriptconsole/" ) ).path();

According to kstandarddirs.h documentation: locateLocal should be used.
Comment 6 Myriam Schweingruber 2016-05-18 17:31:23 UTC
> > But that would still be a bug, right? It shouldn't really crash, but just
> > create the directory.
> Well, as I said, that directory is created correctly in
> ~/.kde/share/apps/amarok/.. in current git master. So either this has been
> fixed since 2.8.90 (which I am sure there was no commit about this), or
> there is something wrong in your installation, trying to install in /usr/..
> instead of the home directory. Not sure there is a bug in Amarok, but I will
> have a look at the code
Seems I spoke a tad fast, there is no directory created in ~/.kde/.. , but in /usr/.. in my local test installation. So apparently the dev only tested in in his local build. I will modify the bug description accordingly.
@Anmol: please check again which variable you use to create this directory (local vs. system), and please test in a system-wide installation
Comment 7 Johannes Huber 2016-05-18 17:36:37 UTC
(In reply to Johannes Huber from comment #5)
> ScriptConsole.cpp: 
> >   if( m_savePath.isEmpty() )
>  >      m_savePath = KUrl( KStandardDirs::locate( "data",
> "amarok/scriptconsole/" ) ).path();
> 
> According to kstandarddirs.h documentation: locateLocal should be used.

A second option would be to extend the 'if'  to check if dir is not writable:
   if( ( m_savePath.isEmpty() || !QDir( m_savePath ).exists() )
        && ( m_savePath = QFileDialog::getExistingDirectory(this, i18n( "Choose where to save your scripts" ), "~",
            QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks) ).isEmpty() )
        return 0;
 ts() )
Comment 8 Myriam Schweingruber 2016-05-18 20:03:51 UTC
Git commit 2900fe47adde10999a6c0f907d73b00a1c1bd5b1 by Myriam Schweingruber.
Committed on 18/05/2016 at 19:59.
Pushed by schweingruber into branch 'master'.

Fix a crash in amarok when opening the Script Console

The script console tries to write to a system folder instead of a user
 folder. Note to devs: always make sure to test a system installation,
 not just a local build.

Thanks to Johannes Huber for the quick fix suggestion.
FIXED-IN: 2.9

M  +1    -1    src/scripting/scriptconsole/ScriptConsole.cpp

http://commits.kde.org/amarok/2900fe47adde10999a6c0f907d73b00a1c1bd5b1