From be745ab965b77f247da85a5f3d4ea73155344b6a Mon Sep 17 00:00:00 2001 From: Clinton Graham Date: Thu, 11 Feb 2021 17:41:30 -0500 Subject: [PATCH 1/2] Fail gracefully if the output directory does not already exist --- islandora_bagit.module | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/islandora_bagit.module b/islandora_bagit.module index d7c7de0..09248ea 100644 --- a/islandora_bagit.module +++ b/islandora_bagit.module @@ -313,6 +313,13 @@ function islandora_bagit_admin_settings() { * a link to 'Download the Bag.' */ function islandora_bagit_create_bag($islandora_object) { + $bag_output_dir = variable_get('islandora_bagit_bag_output_dir', '/tmp'); + if (!file_exists($bag_output_dir)) { + drupal_set_message(t('There is no output Bag directory.'), 'warning'); + watchdog('bagit', 'BagIt Bag not created for !object: output directory missing.', + array('!object' => $islandora_object->id)); + throw new Exception('Missing output bag directory '.$bag_output_dir); + } // First, check to see if the object is a collection, and if it is, // reroute to the relevant batch function. foreach ($islandora_object as $ds) { @@ -349,7 +356,7 @@ function islandora_bagit_create_bag($islandora_object) { } $bag_file_name = variable_get('islandora_bagit_bag_name', 'Bag-') . $pid; - $bag_output_path = variable_get('islandora_bagit_bag_output_dir', '/tmp') . + $bag_output_path = $bag_output_dir . DIRECTORY_SEPARATOR . $bag_file_name; // Because the BagItPHP library does some things by default if the bag output From 0e8f5474a6f1a6b25ae5f16cf7710672b07b1ddd Mon Sep 17 00:00:00 2001 From: Clinton Graham Date: Thu, 25 Mar 2021 11:42:29 -0500 Subject: [PATCH 2/2] Add spaces for code sniffer --- islandora_bagit.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islandora_bagit.module b/islandora_bagit.module index 09248ea..4bc8da5 100644 --- a/islandora_bagit.module +++ b/islandora_bagit.module @@ -318,7 +318,7 @@ function islandora_bagit_create_bag($islandora_object) { drupal_set_message(t('There is no output Bag directory.'), 'warning'); watchdog('bagit', 'BagIt Bag not created for !object: output directory missing.', array('!object' => $islandora_object->id)); - throw new Exception('Missing output bag directory '.$bag_output_dir); + throw new Exception('Missing output bag directory ' . $bag_output_dir); } // First, check to see if the object is a collection, and if it is, // reroute to the relevant batch function.