loonfs_api/options.rs
1//! Per-operation option shapes shared by the runtime and client surfaces.
2//!
3//! `loonfs` (embedded runtime) and `loonfs-client` (HTTP client) expose the
4//! same semantic filesystem operations, so the options that parameterize them
5//! are defined once here and re-exported by both under their existing names.
6//! Keeping one definition is what stops the two surfaces from drifting a
7//! field apart.
8//!
9//! There is one type per operation, even where two of them currently hold the
10//! same fields: options follow the operation they parameterize, so a guard
11//! added to one is not silently offered on the others.
12//!
13//! These are plain in-process argument structs, not wire shapes: nothing here
14//! serializes. The request bodies that do cross the wire live in
15//! [`crate::v0`], and each surface resolves these options into one.
16
17use crate::{CommitId, DeleteDirectoryBehavior, DestinationBehavior, InodeId, RevisionNo};
18
19/// Options for writing a file path.
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub struct PutFileOptions {
22 /// Create-only or replace-existing behavior.
23 pub behavior: DestinationBehavior,
24 /// Idempotency key for the commit; retrying with the same id replays the
25 /// landed commit instead of double-committing. A fresh id is
26 /// generated when absent.
27 pub commit_id: Option<CommitId>,
28 /// Annotation recorded on the commit; part of the commit's identity, so
29 /// the same `commit_id` with a different message is a
30 /// `commit_id_reuse_conflict`.
31 pub message: Option<String>,
32 /// Replace only while the file's current revision is still this one.
33 /// Requires `Replace` behavior; a raced write fails instead of stacking a
34 /// revision on state the caller never saw.
35 pub expected_revision_no: Option<RevisionNo>,
36}
37
38impl Default for PutFileOptions {
39 fn default() -> Self {
40 Self {
41 behavior: DestinationBehavior::NoReplace,
42 commit_id: None,
43 message: None,
44 expected_revision_no: None,
45 }
46 }
47}
48
49/// Options for creating a directory.
50#[derive(Debug, Clone, PartialEq, Eq, Default)]
51pub struct CreateDirectoryOptions {
52 /// Optional idempotency key.
53 pub commit_id: Option<CommitId>,
54 /// Annotation recorded on the commit; part of the commit's identity.
55 pub message: Option<String>,
56 /// Also create missing ancestor directories, like `put_file` does.
57 pub parents: bool,
58}
59
60/// Options for deleting a path.
61#[derive(Debug, Clone, PartialEq, Eq)]
62pub struct DeleteOptions {
63 /// Directory delete behavior.
64 pub behavior: DeleteDirectoryBehavior,
65 /// Optional idempotency key.
66 pub commit_id: Option<CommitId>,
67 /// Annotation recorded on the commit; part of the commit's identity.
68 pub message: Option<String>,
69 /// When set, the delete applies only while the path still resolves to
70 /// this inode, so a raced rebinding fails instead of deleting the wrong
71 /// inode.
72 pub expected_inode_id: Option<InodeId>,
73}
74
75impl Default for DeleteOptions {
76 fn default() -> Self {
77 Self {
78 behavior: DeleteDirectoryBehavior::NonRecursive,
79 commit_id: None,
80 message: None,
81 expected_inode_id: None,
82 }
83 }
84}
85
86/// Options for moving a path.
87#[derive(Debug, Clone, PartialEq, Eq, Default)]
88pub struct MoveOptions {
89 /// Create-only or replace-existing behavior for the destination.
90 pub behavior: DestinationBehavior,
91 /// Optional idempotency key.
92 pub commit_id: Option<CommitId>,
93 /// Annotation recorded on the commit; part of the commit's identity.
94 pub message: Option<String>,
95}
96
97/// Options for copying a file path.
98#[derive(Debug, Clone, PartialEq, Eq, Default)]
99pub struct CopyOptions {
100 /// Create-only or replace-existing behavior for the destination.
101 pub behavior: DestinationBehavior,
102 /// Optional idempotency key.
103 pub commit_id: Option<CommitId>,
104 /// Annotation recorded on the commit; part of the commit's identity.
105 pub message: Option<String>,
106}
107
108/// Options for restoring a file revision by path.
109#[derive(Debug, Clone, PartialEq, Eq, Default)]
110pub struct RestoreRevisionOptions {
111 /// Optional idempotency key.
112 pub commit_id: Option<CommitId>,
113 /// Annotation recorded on the commit; part of the commit's identity.
114 pub message: Option<String>,
115}
116
117/// Options for recovering a deleted file or subtree.
118#[derive(Debug, Clone, PartialEq, Eq, Default)]
119pub struct UndeleteOptions {
120 /// Optional idempotency key.
121 pub commit_id: Option<CommitId>,
122 /// Annotation recorded on the commit; part of the commit's identity.
123 pub message: Option<String>,
124}