PluginAPI::writeScore returns true although saving with relative path failed

• May 13, 2019 - 12:53
Reported version
3.0
Priority
P3 - Low
Type
Plugins
Frequency
Once
Severity
S4 - Minor
Reproducibility
Always
Status
active
Regression
No
Workaround
Yes
Project
Tags

Running the following plugin the value of written that is logged is true, but no file was created. And no indication of failure was logged.

import QtQuick 2.0
import MuseScore 3.0

MuseScore {
    menuPath: "Plugins.Save with Timestamp"
    description: "Save the score as mscz to the current directory using workTitle_Timestamp as filename\nTimestamp is in the format YYYYMMDD-HHMMSS"
    version: "1.0"
    requiresScore: true
    onRun: {
        var newFileName = curScore.metaTag("workTitle");
        var timestamp = (new Date()).toISOString(); //format ISO 8601 YYYY-MM-DDTHH:MM:SS.mmmZ
        var timestampFilter = /(\d+)\-(\d+)\-(\d+)T(\d+):(\d+):(\d+)\.\d+Z/;
        var timestampReformat = '$1$2$3-$4$5$6';
        newFileName += '_' + timestamp.replace(timestampFilter, timestampReformat);
console.log(newFileName);
        var written = writeScore(curScore, newFileName, 'mscz');
console.log(written);
        Qt.quit();
    }
}

Workaround is to ensure the provided newFileName contains an absolute path such as var newFileName = "C:\\Users\\jeetee\\Documents\\" + curScore.metaTag("workTitle");

Reason for the failure could be that the relative path provided is relative to the current working directory. On (my) Windows, this would equal somewhere within Program Files, where a normal user has no writing access. I'd half expected the path to be relative compared to the current score being passed in; don't think doing so would have negative repercussions.

The issue to fix is to return false in case of failing to save the file. That assumes this type of failure can be detected however…