Skip to main content

rustfs_replication/
storage_api.rs

1// Copyright 2024 RustFS Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::{ReplicationState, ReplicationStatusType, VersionPurgeStatusType};
16use time::OffsetDateTime;
17use uuid::Uuid;
18
19#[derive(Debug, Default, Clone)]
20pub struct ObjectToDelete {
21    pub object_name: String,
22    pub version_id: Option<Uuid>,
23    pub delete_marker_replication_status: Option<String>,
24    pub version_purge_status: Option<VersionPurgeStatusType>,
25    pub version_purge_statuses: Option<String>,
26    pub replicate_decision_str: Option<String>,
27}
28
29impl ObjectToDelete {
30    pub fn replication_state(&self) -> ReplicationState {
31        ReplicationState {
32            replication_status_internal: self.delete_marker_replication_status.clone(),
33            version_purge_status_internal: self.version_purge_statuses.clone(),
34            replicate_decision_str: self.replicate_decision_str.clone().unwrap_or_default(),
35            targets: crate::replication_statuses_map(self.delete_marker_replication_status.as_deref().unwrap_or_default()),
36            purge_targets: crate::version_purge_statuses_map(self.version_purge_statuses.as_deref().unwrap_or_default()),
37            ..Default::default()
38        }
39    }
40}
41
42#[derive(Debug, Default, Clone)]
43pub struct DeletedObject {
44    pub delete_marker: bool,
45    pub delete_marker_version_id: Option<Uuid>,
46    pub object_name: String,
47    pub version_id: Option<Uuid>,
48    pub delete_marker_mtime: Option<OffsetDateTime>,
49    pub replication_state: Option<ReplicationState>,
50    pub found: bool,
51    pub force_delete: bool,
52    pub force_delete_id: Option<Uuid>,
53    pub force_delete_target_arns: Vec<String>,
54    pub force_delete_generation: Option<i64>,
55}
56
57impl DeletedObject {
58    pub fn version_purge_status(&self) -> VersionPurgeStatusType {
59        self.replication_state
60            .as_ref()
61            .map(|v| v.composite_version_purge_status())
62            .unwrap_or(VersionPurgeStatusType::Empty)
63    }
64
65    pub fn delete_marker_replication_status(&self) -> ReplicationStatusType {
66        self.replication_state
67            .as_ref()
68            .map(|v| v.composite_replication_status())
69            .unwrap_or(ReplicationStatusType::Empty)
70    }
71}