catalyst / moodle-report_coursesize

upgraded coursesize report
14 stars 19 forks source link

Invalid Filepath Value #18

Closed RussellEngland closed 3 years ago

RussellEngland commented 4 years ago

If the path in $CFG->dataroot doesn't have a slash at the end, then this error is displayed

Coding error detected, it must be fixed by a programmer: Invalid Filepath Value

More information about this error
Debug info:
Error code: codingerror
Stack trace: * line 264 of /lib/classes/command/argument.php: core\command\exception thrown

line 138 of /lib/classes/command/argument.php: call to core\command\argument::validate_full_filepath()
line 183 of /lib/classes/command/executable.php: call to core\command\argument->set_value()
line 7088 of /lib/moodlelib.php: call to core\command\executable->add_value()
line 56 of /report/coursesize/index.php: call to get_directory_size()

So in /report/coursesize/index.php, change this

    $totalusage = get_directory_size($CFG->dataroot);

To this

    $rootdir = $CFG->dataroot;
    if (substr($rootdir, -1) !== DIRECTORY_SEPARATOR) {
        $rootdir .= DIRECTORY_SEPARATOR;
    }
    $totalusage = get_directory_size($rootdir);
nwp90 commented 3 years ago

Isn't this fixed by https://github.com/catalyst/moodle-report_coursesize/commit/8a251a71078d5a1e3ce0c49ff521a4ff51dc32f8 (although it doesn't use DIRECTORY_SEPARATOR and perhaps should)?

danmarsden commented 3 years ago

yeah - PHP converts it automatically for windows, but could be other O/S that would need DIRECTORY_SEPARATOR to be used. - I'll close this one but if anyone hits this and wants to change it I'm open to seeing a PR - although, I'd expect many things in core that don't use DIRECTORY_SEPARATOR to fail before someone cares about report_coursesize! :-)