@@ -43,6 +43,9 @@ pub(crate) trait KVStorageTrait {
43
43
hash : & str ,
44
44
) -> Result < ( ) , Box < dyn Error > > {
45
45
let cnt = self . get_ref_count ( bucket, hash) . await ?;
46
+ if cnt == 0 {
47
+ return Ok ( ( ) ) ;
48
+ }
46
49
self . set_ref_count ( bucket, hash, cnt - 1 ) . await
47
50
}
48
51
@@ -87,13 +90,20 @@ impl KVStorage {
87
90
}
88
91
}
89
92
93
+ /**
94
+ * Setup the KV storage.
95
+ */
90
96
pub async fn setup ( & mut self ) -> Result < ( ) , Box < dyn Error > > {
91
97
match self {
92
98
KVStorage :: Postgres ( storage) => storage. setup ( ) . await ,
93
99
KVStorage :: SQLite ( storage) => storage. setup ( ) . await ,
94
100
}
95
101
}
96
102
103
+ /**
104
+ * Get the reference count for a hash.
105
+ * If the hash does not exist, return 0.
106
+ */
97
107
pub async fn get_ref_count ( & mut self , bucket : & str , hash : & str ) -> Result < i32 , Box < dyn Error > > {
98
108
debug ! ( "Getting ref count for bucket: {}, hash: {}" , bucket, hash) ;
99
109
match self {
@@ -102,6 +112,9 @@ impl KVStorage {
102
112
}
103
113
}
104
114
115
+ /**
116
+ * Set the reference count for a hash.
117
+ */
105
118
pub async fn set_ref_count (
106
119
& mut self ,
107
120
bucket : & str ,
@@ -118,6 +131,9 @@ impl KVStorage {
118
131
}
119
132
}
120
133
134
+ /**
135
+ * Increment the reference count for a hash.
136
+ */
121
137
pub async fn increment_ref_count (
122
138
& mut self ,
123
139
bucket : & str ,
@@ -130,6 +146,10 @@ impl KVStorage {
130
146
}
131
147
}
132
148
149
+ /**
150
+ * Decrement the reference count for a hash.
151
+ * If the reference count is already 0, do nothing.
152
+ */
133
153
pub async fn decrement_ref_count (
134
154
& mut self ,
135
155
bucket : & str ,
@@ -142,6 +162,10 @@ impl KVStorage {
142
162
}
143
163
}
144
164
165
+ /**
166
+ * Get the modified time for a path.
167
+ * If the path does not exist, return 0.
168
+ */
145
169
pub async fn get_modified ( & mut self , bucket : & str , path : & str ) -> Result < i64 , Box < dyn Error > > {
146
170
debug ! ( "Getting modified time for bucket: {}, path: {}" , bucket, path) ;
147
171
match self {
@@ -150,6 +174,9 @@ impl KVStorage {
150
174
}
151
175
}
152
176
177
+ /**
178
+ * Set the modified time for a path.
179
+ */
153
180
pub async fn set_modified (
154
181
& mut self ,
155
182
bucket : & str ,
@@ -166,6 +193,9 @@ impl KVStorage {
166
193
}
167
194
}
168
195
196
+ /**
197
+ * Delete the modified time for a path.
198
+ */
169
199
pub async fn delete_modified (
170
200
& mut self ,
171
201
bucket : & str ,
@@ -178,6 +208,10 @@ impl KVStorage {
178
208
}
179
209
}
180
210
211
+ /**
212
+ * Get the reference file for a path.
213
+ * If the path does not exist, return an empty string.
214
+ */
181
215
pub async fn get_ref_file (
182
216
& mut self ,
183
217
bucket : & str ,
@@ -190,6 +224,9 @@ impl KVStorage {
190
224
}
191
225
}
192
226
227
+ /**
228
+ * Set the reference file for a path.
229
+ */
193
230
pub async fn set_ref_file (
194
231
& mut self ,
195
232
bucket : & str ,
@@ -206,6 +243,9 @@ impl KVStorage {
206
243
}
207
244
}
208
245
246
+ /**
247
+ * Delete the reference file for a path.
248
+ */
209
249
pub async fn delete_ref_file (
210
250
& mut self ,
211
251
bucket : & str ,
0 commit comments