{
ArrayList<String> dataFiles = new ArrayList<String>();
ArrayList<String> newFiles = new ArrayList<String>();
ArrayList<Pair<String, String>> renames = new ArrayList<Pair<String, String>>();
SequentialFile controlFile = JournalCompactor.readControlFile(fileFactory, dataFiles, newFiles, renames);
if (controlFile != null)
{
for (String dataFile : dataFiles)
{
SequentialFile file = fileFactory.createSequentialFile(dataFile, 1);
if (file.exists())
{
file.delete();
}
}
for (String newFile : newFiles)
{
SequentialFile file = fileFactory.createSequentialFile(newFile, 1);
if (file.exists())
{
final String originalName = file.getFileName();
final String newName = originalName.substring(0, originalName.lastIndexOf(".cmp"));
file.renameTo(newName);
}
}
for (Pair<String, String> rename : renames)
{
SequentialFile fileTmp = fileFactory.createSequentialFile(rename.a, 1);
SequentialFile fileTo = fileFactory.createSequentialFile(rename.b, 1);
// We should do the rename only if the tmp file still exist, or else we could
// delete a valid file depending on where the crash occured during the control file delete
if (fileTmp.exists())
{
fileTo.delete();
fileTmp.renameTo(rename.b);
}
}
controlFile.delete();