Search in sources :

Example 1 with FileDeleteTransactionRunnable

use of org.xwiki.store.FileDeleteTransactionRunnable in project xwiki-platform by xwiki.

the class FilesystemAttachmentRecycleBinContentStore method getDeletedAttachmentPurgeRunnable.

/**
 * Get a TransactionRunnable for removing a deleted attachment from the filesystem entirely.
 *
 * @param provider the file provider for the deleted attachment to purge from the recycle bin.
 * @return a StartableTransactionRunnable for removing the attachment.
 */
private StartableTransactionRunnable getDeletedAttachmentPurgeRunnable(final DeletedAttachmentFileProvider provider) {
    final StartableTransactionRunnable out = new StartableTransactionRunnable();
    final File deletedAttachDir = provider.getDeletedAttachmentMetaFile().getParentFile();
    if (!deletedAttachDir.exists()) {
        // No such dir, return a do-nothing runnable.
        return out;
    }
    // Easy thing to do is just delete everything in the deleted-attachment directory.
    for (File toDelete : deletedAttachDir.listFiles()) {
        new FileDeleteTransactionRunnable(toDelete, this.fileTools.getBackupFile(toDelete), this.fileTools.getLockForFile(toDelete)).runIn(out);
    }
    return out;
}
Also used : FileDeleteTransactionRunnable(org.xwiki.store.FileDeleteTransactionRunnable) StartableTransactionRunnable(org.xwiki.store.StartableTransactionRunnable) File(java.io.File)

Example 2 with FileDeleteTransactionRunnable

use of org.xwiki.store.FileDeleteTransactionRunnable in project xwiki-platform by xwiki.

the class FilesystemRecycleBinContentStore method delete.

@Override
public void delete(DocumentReference reference, long index, boolean bTransaction) throws XWikiException {
    final XWikiContext xcontext = this.xcontextProvider.get();
    final XWikiHibernateTransaction transaction = new XWikiHibernateTransaction(xcontext);
    final File contentFile = this.fileTools.getDeletedDocumentFileProvider(reference, index).getDeletedDocumentContentFile();
    new FileDeleteTransactionRunnable(contentFile, this.fileTools.getBackupFile(contentFile), this.fileTools.getLockForFile(contentFile)).runIn(transaction);
    try {
        transaction.start();
    } catch (Exception e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SAVING_ATTACHMENT, "Exception while deleting deleted document content.", e);
    }
}
Also used : FileDeleteTransactionRunnable(org.xwiki.store.FileDeleteTransactionRunnable) XWikiContext(com.xpn.xwiki.XWikiContext) File(java.io.File) XWikiException(com.xpn.xwiki.XWikiException) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

File (java.io.File)2 FileDeleteTransactionRunnable (org.xwiki.store.FileDeleteTransactionRunnable)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 StartableTransactionRunnable (org.xwiki.store.StartableTransactionRunnable)1