diskusagereports icon indicating copy to clipboard operation
diskusagereports copied to clipboard

Processing broken under PHP 8.1 after Ubuntu release upgrade

Open jheidel opened this issue 3 years ago • 0 comments

This project broke for me after migration from Ubuntu 20.04 to 22.04. I think the default PHP version was bumped from 7 to 8 as part of this upgrade which is likely responsible.

$ php -v
PHP 8.1.2-1ubuntu2.9 (cli) (built: Oct 19 2022 14:58:09) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2-1ubuntu2.9, Copyright (c), by Zend Technologies

I'm getting the following error:

$ /bin/bash find.sh /data/share/downloads/ > /tmp/find.txt
$ cat /tmp/find.txt | /usr/bin/php process.php -v -vv /tmp/report
PHP Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /home/jeff/sources/diskusagereports/scripts/process.php on line 286
  Processing filelist...
  Processing header...
FAIL: The header line in the <filelist> is invalid:
#

I'm no expert in php, but I found that after making the following changes I was able to get it to work:

  • Class constructors need to use __construct() or else they don't run
  • The comparator function needs to be static or this throws an error
  • Switch to break instead of continue inside switch (fix warning)

After making these changes the report appears to be generated correctly.

cat /tmp/find.txt | /usr/bin/php process.php -v /data/media/test/report
  Processing filelist...
  Saving dir tree...
  Saving settings...
  Complete! Processed 6,762 lines from 810.04 KB, wrote 1.61 MB in 1,056 files, took 0 seconds.

I will submit these fixes as a pull request. I'm not sure if this project is still maintained but even if not hopefully this will save someone else some debugging time.

jheidel avatar Nov 25 '22 17:11 jheidel