Search in sources :

Example 1 with FileDeletionEvent

use of org.commonjava.maven.galley.event.FileDeletionEvent in project indy by Commonjava.

the class MergedFileUploadListener method reMerge.

private void reMerge(final Group group, final String path) throws IOException {
    logger.debug("Updating merged metadata file: {} in group: {}", path, group.getKey());
    final Transfer[] toDelete = { fileManager.getStorageReference(group, path), fileManager.getStorageReference(group, path + GroupMergeHelper.MERGEINFO_SUFFIX), fileManager.getStorageReference(group, path + GroupMergeHelper.SHA_SUFFIX), fileManager.getStorageReference(group, path + GroupMergeHelper.MD5_SUFFIX) };
    for (final Transfer item : toDelete) {
        logger.debug("Attempting to delete: {}", item);
        if (item.exists()) {
            final boolean result = item.delete();
            logger.debug("Deleted: {} (success? {})", item, result);
            if (fileEvent != null) {
                logger.debug("Firing deletion event for: {}", item);
                fileEvent.fire(new FileDeletionEvent(item, new EventMetadata()));
            }
        }
    }
}
Also used : Transfer(org.commonjava.maven.galley.model.Transfer) FileDeletionEvent(org.commonjava.maven.galley.event.FileDeletionEvent) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 2 with FileDeletionEvent

use of org.commonjava.maven.galley.event.FileDeletionEvent in project galley by Commonjava.

the class Transfer method delete.

public boolean delete(final boolean fireEvents, final EventMetadata eventMetadata) throws IOException {
    provider.waitForWriteUnlock(resource);
    try {
        if (decorator != null) {
            decorator.decorateDelete(this, eventMetadata);
        }
        Logger contentLogger = LoggerFactory.getLogger(DELETE_CONTENT_LOG);
        if (contentLogger.isTraceEnabled()) {
            contentLogger.trace("Starting delete of: {} ({}) from:\n    ", resource, eventMetadata, join(Thread.currentThread().getStackTrace(), "\n    "));
        } else {
            contentLogger.info("Starting delete of: {} ({})", resource, eventMetadata);
        }
        final boolean deleted = provider.delete(resource);
        if (deleted) {
            contentLogger.info("Finished delete of: {}", resource);
            if (fireEvents) {
                fileEventManager.fire(new FileDeletionEvent(this, eventMetadata));
            }
        } else {
            contentLogger.info("Failed to delete: {}", resource);
        }
        return deleted;
    } catch (final IOException e) {
        if (fireEvents) {
            fileEventManager.fire(new FileErrorEvent(this, e, eventMetadata));
        }
        throw e;
    }
}
Also used : FileErrorEvent(org.commonjava.maven.galley.event.FileErrorEvent) FileDeletionEvent(org.commonjava.maven.galley.event.FileDeletionEvent) IOException(java.io.IOException) Logger(org.slf4j.Logger)

Aggregations

FileDeletionEvent (org.commonjava.maven.galley.event.FileDeletionEvent)2 IOException (java.io.IOException)1 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)1 FileErrorEvent (org.commonjava.maven.galley.event.FileErrorEvent)1 Transfer (org.commonjava.maven.galley.model.Transfer)1 Logger (org.slf4j.Logger)1