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