Skip to main content

qubit_fs/options/
copy_options.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10//! Copy operation options and policy types.
11
12use qubit_metadata::MetadataFilter;
13
14use crate::{
15    CopyConflictPolicy,
16    CopyMode,
17    MetadataPreservePolicy,
18    ProgressPolicy,
19    ServerSidePreference,
20};
21
22/// Options controlling file, object, or tree copy operations.
23#[derive(Clone, Debug, PartialEq)]
24pub struct CopyOptions {
25    /// Copy source interpretation mode.
26    pub mode: CopyMode,
27    /// Destination conflict policy.
28    pub conflict: CopyConflictPolicy,
29    /// Metadata preservation policy.
30    pub preserve_metadata: MetadataPreservePolicy,
31    /// Server-side copy preference.
32    pub server_side: ServerSidePreference,
33    /// Whether symbolic links should be followed.
34    pub follow_symlinks: bool,
35    /// Whether missing destination parents should be created.
36    pub create_parent: bool,
37    /// Whether tree copy should continue after per-entry failures.
38    pub continue_on_error: bool,
39    /// Optional metadata filter for tree copy.
40    pub filter: Option<MetadataFilter>,
41    /// Progress collection policy.
42    pub progress: ProgressPolicy,
43}
44
45impl CopyOptions {
46    /// Creates options for copying one file-like resource.
47    ///
48    /// # Returns
49    /// Copy options with `mode` set to [`CopyMode::File`].
50    #[inline]
51    #[must_use]
52    pub fn file() -> Self {
53        Self {
54            mode: CopyMode::File,
55            ..Self::default()
56        }
57    }
58
59    /// Creates options for copying a resource tree.
60    ///
61    /// # Returns
62    /// Copy options with `mode` set to [`CopyMode::Tree`].
63    #[inline]
64    #[must_use]
65    pub fn tree() -> Self {
66        Self {
67            mode: CopyMode::Tree,
68            ..Self::default()
69        }
70    }
71}
72
73impl Default for CopyOptions {
74    #[inline]
75    fn default() -> Self {
76        Self {
77            mode: CopyMode::Auto,
78            conflict: CopyConflictPolicy::Fail,
79            preserve_metadata: MetadataPreservePolicy::Portable,
80            server_side: ServerSidePreference::Prefer,
81            follow_symlinks: false,
82            create_parent: false,
83            continue_on_error: false,
84            filter: None,
85            progress: ProgressPolicy::CountOnly,
86        }
87    }
88}