s3sync 1.58.6

Reliable, flexible, and fast synchronization tool for S3.
Documentation
use async_trait::async_trait;
use aws_sdk_s3::types::ChecksumAlgorithm;
use aws_smithy_types::DateTime;
use bitflags::bitflags;

bitflags! {
    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
    pub struct EventType: u64 {
        // Sync statistics report events are not captured by the pipeline.
        // Maybe there is no need to capture these events
        // the pipeline captures only synchronization events.

        const UNDEFINED = 0u64;
        const PIPELINE_START = 1u64 << 1;
        const PIPELINE_END = 1u64 << 2;

        // The following events occur per object during the sync process
        const SYNC_START = 1u64 << 3;
        const SYNC_COMPLETE = 1u64 << 4;
        const SYNC_DELETE =  1u64 << 5;

        // The following events occur after the SYNC_COMPLETE event
        const SYNC_ETAG_VERIFIED = 1u64 << 6;
        const SYNC_CHECKSUM_VERIFIED = 1u64 << 7;
        const SYNC_ETAG_MISMATCH = 1u64 << 8;
        const SYNC_CHECKSUM_MISMATCH = 1u64 << 9;

        // Not all warnings trigger this event, but it is used for general (useful for crate user) warnings
        const SYNC_WARNING = 1u64 << 10;

        // If an error occurs during the pipeline, this event is triggered and the pipeline is stopped
        const PIPELINE_ERROR = 1u64 << 11;

        // If a syncing object is cancelled by preprocess callback, this event is triggered
        const SYNC_CANCEL = 1u64 << 12;

        // If an object (or part of an object) is written, this event is triggered
        const SYNC_WRITE = 1u64 << 13;

        // If an object is filtered out, this event is triggered. EventData.message will contain the reason for filtering.
        const SYNC_FILTERED = 1u64 << 14;

        // This event is triggered after the PIPELINE_END event
        const STATS_REPORT = 1u64 << 15;

        // This is a special event mask to indicate that all events should be captured
        const ALL_EVENTS  = !0;
    }
}

#[derive(Default, Debug, Clone)]
pub struct EventData {
    pub event_type: EventType,
    pub dry_run: bool,
    pub key: Option<String>,
    pub source_version_id: Option<String>,
    pub target_version_id: Option<String>,
    pub source_last_modified: Option<DateTime>,
    pub target_last_modified: Option<DateTime>,
    pub source_size: Option<u64>,
    pub target_size: Option<u64>,
    pub checksum_algorithm: Option<ChecksumAlgorithm>,
    pub source_checksum: Option<String>,
    pub target_checksum: Option<String>,
    pub source_etag: Option<String>,
    pub target_etag: Option<String>,
    pub source_content_type: Option<String>,
    pub source_user_defined_metadata: Option<String>,
    pub source_tagging: Option<String>,
    pub byte_written: Option<u64>,
    pub upload_id: Option<String>,
    pub part_number: Option<u64>,
    pub message: Option<String>,
    pub stats_transferred_byte: Option<u64>,
    pub stats_transferred_byte_per_sec: Option<u64>,
    pub stats_transferred_object: Option<u64>,
    pub stats_transferred_object_per_sec: Option<u64>,
    pub stats_etag_verified: Option<u64>,
    pub stats_etag_mismatch: Option<u64>,
    pub stats_checksum_verified: Option<u64>,
    pub stats_checksum_mismatch: Option<u64>,
    pub stats_deleted: Option<u64>,
    pub stats_skipped: Option<u64>,
    pub stats_error: Option<u64>,
    pub stats_warning: Option<u64>,
    pub stats_duration_sec: Option<f64>,
}

impl EventData {
    pub fn new(event_type: EventType) -> Self {
        Self {
            event_type,
            ..Default::default()
        }
    }
}

#[async_trait]
pub trait EventCallback {
    async fn on_event(&mut self, event_data: EventData);
}