whikloj / BagItTools

A PHP BagIt library
MIT License
11 stars 5 forks source link

Handling creation errors #19

Closed henning-gerhardt closed 3 years ago

henning-gerhardt commented 3 years ago

If your destination directory or nfs share get out of space or get by accident remounted read-only or through some other reason the creating of directories and files are failing there is no reaction except PHP Warnings like

PHP Warning:  mkdir(): No space left on device in /<path_to_application>/vendor/whikloj/bagittools/src/Bag.php on line 1142
PHP Warning:  file_put_contents(/<path_to_bag>/bagit.txt): failed to open stream: No such file or directory in /<path_to_application>/vendor/whikloj/bagittools/src/Bag.php on line 1749
PHP Warning:  copy(/<path_to_bag>/data/<some_file>): failed to open stream: No space left on device in /<path_to_application>/vendor/whikloj/bagittools/src/Bag.php on line 441

Return values of uses methods like mkdir(), copy(), file_put_contents(), ... should be evaluated and in case of an error maybe an exception with a good error message should thrown or something similar should be done.