mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
[DS-372] New verbose option for [dspace]/bin/dspace cleanup script
git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@4519 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -385,7 +385,7 @@ public class BitstreamStorageManager
|
||||
* @return The ID of the registered bitstream
|
||||
* @exception SQLException
|
||||
* If a problem occurs accessing the RDBMS
|
||||
* @throws IOExeption
|
||||
* @throws IOException
|
||||
*/
|
||||
public static int register(Context context, int assetstore,
|
||||
String bitstreamPath) throws SQLException, IOException {
|
||||
@@ -595,7 +595,7 @@ public class BitstreamStorageManager
|
||||
* @exception SQLException
|
||||
* If a problem occurs accessing the RDBMS
|
||||
*/
|
||||
public static void cleanup(boolean deleteDbRecords) throws SQLException, IOException
|
||||
public static void cleanup(boolean deleteDbRecords, boolean verbose) throws SQLException, IOException
|
||||
{
|
||||
Context context = null;
|
||||
BitstreamInfoDAO bitstreamInfoDAO = new BitstreamInfoDAO();
|
||||
@@ -624,7 +624,9 @@ public class BitstreamStorageManager
|
||||
if (deleteDbRecords)
|
||||
{
|
||||
log.debug("deleting record");
|
||||
if (verbose) System.out.println(" - Deleting bitstream information (ID: " + bid + ")");
|
||||
bitstreamInfoDAO.deleteBitstreamInfoWithHistory(bid);
|
||||
if (verbose) System.out.println(" - Deleting bitstream record from database (ID: " + bid + ")");
|
||||
DatabaseManager.delete(context, "Bitstream", bid);
|
||||
}
|
||||
continue;
|
||||
@@ -641,7 +643,9 @@ public class BitstreamStorageManager
|
||||
if (deleteDbRecords)
|
||||
{
|
||||
log.debug("deleting db record");
|
||||
if (verbose) System.out.println(" - Deleting bitstream information (ID: " + bid + ")");
|
||||
bitstreamInfoDAO.deleteBitstreamInfoWithHistory(bid);
|
||||
if (verbose) System.out.println(" - Deleting bitstream record from database (ID: " + bid + ")");
|
||||
DatabaseManager.delete(context, "Bitstream", bid);
|
||||
}
|
||||
|
||||
@@ -651,12 +655,14 @@ public class BitstreamStorageManager
|
||||
|
||||
boolean success = file.delete();
|
||||
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug("Deleted bitstream " + bid + " (file "
|
||||
String message = ("Deleted bitstream " + bid + " (file "
|
||||
+ file.getAbsolutePath() + ") with result "
|
||||
+ success);
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug(message);
|
||||
}
|
||||
if (verbose) System.out.println(message);
|
||||
|
||||
// if the file was deleted then
|
||||
// try deleting the parents
|
||||
@@ -677,7 +683,9 @@ public class BitstreamStorageManager
|
||||
commit_counter++;
|
||||
if (commit_counter % 100 == 0)
|
||||
{
|
||||
System.out.print("Committing changes to the database...");
|
||||
context.commit();
|
||||
System.out.println(" Done!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -688,11 +696,13 @@ public class BitstreamStorageManager
|
||||
// time around will be a no-op.
|
||||
catch (SQLException sqle)
|
||||
{
|
||||
if (verbose) System.err.println("Error: " + sqle.getMessage());
|
||||
context.abort();
|
||||
throw sqle;
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
if (verbose) System.err.println("Error: " + ioe.getMessage());
|
||||
context.abort();
|
||||
throw ioe;
|
||||
}
|
||||
|
@@ -79,6 +79,7 @@ public class Cleanup
|
||||
Options options = new Options();
|
||||
|
||||
options.addOption("l", "leave", false, "Leave database records but delete file from assetstore");
|
||||
options.addOption("v", "verbose", false, "Provide verbose output");
|
||||
options.addOption("h", "help", false, "Help");
|
||||
|
||||
try
|
||||
@@ -106,7 +107,7 @@ public class Cleanup
|
||||
deleteDbRecords = false;
|
||||
}
|
||||
log.debug("leave db records = " + deleteDbRecords);
|
||||
BitstreamStorageManager.cleanup(deleteDbRecords);
|
||||
BitstreamStorageManager.cleanup(deleteDbRecords, line.hasOption('v'));
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ BINDIR=`dirname $0`
|
||||
|
||||
echo "Cleaning the asset store"
|
||||
|
||||
$BINDIR/dsrun org.dspace.storage.bitstore.Cleanup
|
||||
$BINDIR/dsrun org.dspace.storage.bitstore.Cleanup "$@"
|
||||
|
||||
echo "Cleanup completed"
|
||||
|
||||
|
Reference in New Issue
Block a user