diff --git a/src/api2/admin/datastore/backup.rs b/src/api2/admin/datastore/backup.rs index 10ef4774..d1986a04 100644 --- a/src/api2/admin/datastore/backup.rs +++ b/src/api2/admin/datastore/backup.rs @@ -144,6 +144,10 @@ fn backup_api() -> Router { .download(api_method_dynamic_chunk_index()) .post(api_method_create_dynamic_index()) ) + .subdir( + "dynamic_close", Router::new() + .post(api_method_close_dynamic_index()) + ) .subdir("test1", test1) .subdir("test2", test2) .list_subdirs(); @@ -200,13 +204,40 @@ fn create_dynamic_index( Ok(json!(uid)) } +pub fn api_method_close_dynamic_index() -> ApiMethod { + ApiMethod::new( + close_dynamic_index, + ObjectSchema::new("Close dynamic index writer.") + .required("wid", IntegerSchema::new("Dynamic writer ID.") + .minimum(1) + .maximum(256) + ) + ) +} + +fn close_dynamic_index ( + param: Value, + _info: &ApiMethod, + rpcenv: &mut RpcEnvironment, +) -> Result { + + let wid = tools::required_integer_param(¶m, "wid")? as usize; + + let env: &BackupEnvironment = rpcenv.as_ref(); + + env.dynamic_writer_close(wid)?; + + Ok(Value::Null) +} + + + fn test1_get ( _param: Value, _info: &ApiMethod, rpcenv: &mut RpcEnvironment, ) -> Result { - println!("TYPEID {:?}", (*rpcenv).type_id()); let env: &BackupEnvironment = rpcenv.as_ref(); diff --git a/src/api2/admin/datastore/backup/environment.rs b/src/api2/admin/datastore/backup/environment.rs index 8f569aa7..66b954f0 100644 --- a/src/api2/admin/datastore/backup/environment.rs +++ b/src/api2/admin/datastore/backup/environment.rs @@ -89,6 +89,20 @@ impl BackupEnvironment { Ok(()) } + /// Close dynamic writer + pub fn dynamic_writer_close(&self, wid: usize) -> Result<(), Error> { + let mut state = self.state.lock().unwrap(); + + let mut data = match state.dynamic_writers.remove(&wid) { + Some(data) => data, + None => bail!("dynamic writer '{}' not registered", wid), + }; + + data.1.close()?; + + Ok(()) + } + pub fn log>(&self, msg: S) { self.worker.log(msg); }