@@ -147,14 +147,21 @@ function config!(proj::AbstractTomlFileDataProject, dataset::DataSet; kws...)
147
147
if data_project (dataset) != = proj
148
148
error (" dataset must belong to project" )
149
149
end
150
- # Here we accept the update independently of the project - Data.toml should
151
- # be able to manage any dataset config.
152
- config! (nothing , dataset; kws... )
153
- set_cache (proj, project_toml (get_cache (proj, false )))
150
+ _save_project (proj) do inner_proj
151
+ # Here we accept the update independently of the project - Data.toml
152
+ # should be able to manage any dataset config.
153
+ config! (nothing , dataset; kws... )
154
+ inner_proj
155
+ end
154
156
return dataset
155
157
end
156
158
157
- function create (proj:: AbstractTomlFileDataProject , name;
159
+ function _save_project (f:: Function , proj:: AbstractTomlFileDataProject )
160
+ p = f (get_cache (proj, false ))
161
+ set_cache (proj, project_toml (p))
162
+ end
163
+
164
+ function create! (proj:: AbstractTomlFileDataProject , name;
158
165
# One of the following required
159
166
source:: Union{Nothing,DataSet} = nothing ,
160
167
driver:: Union{Nothing,AbstractString} = nothing ,
@@ -228,28 +235,26 @@ end
228
235
project_name (proj:: TomlFileDataProject ) = proj. path
229
236
230
237
function Base. setindex! (proj:: TomlFileDataProject , data:: DataSet , name:: AbstractString )
231
- p = get_cache (proj)
232
- p[name] = data
233
- save_project (proj. path, p)
238
+ _save_project (proj) do inner_proj
239
+ inner_proj[name] = data
240
+ inner_proj
241
+ end
234
242
end
235
243
236
- function delete (proj:: TomlFileDataProject , name:: AbstractString )
237
- # FIXME : Make this safe for concurrent use in-process
238
- # (or better, between processes?)
239
- p = get_cache (proj)
244
+ function Base. delete! (proj:: TomlFileDataProject , name:: AbstractString )
245
+ _save_project (proj) do inner_proj
246
+ ds = dataset (inner_proj, name)
247
+ # Assume all datasets which don't have the "linked" property are linked.
248
+ # This prevents us accidentally deleting data.
249
+ if get (ds, " linked" , true )
250
+ @info " Linked dataset is preserved on data storage" name
251
+ else
252
+ driver = _find_driver (ds)
253
+ delete_storage (proj, driver, ds)
254
+ end
240
255
241
- ds = dataset (p, name)
242
- # Assume all datasets which don't have the "linked" property are linked.
243
- # This prevents us accidentally deleting data.
244
- if get (ds, " linked" , true )
245
- @info " Linked dataset is preserved on data storage" name
246
- else
247
- driver = _find_driver (ds)
248
- delete_storage (proj, driver, ds)
256
+ Base. delete! (inner_proj, name)
249
257
end
250
-
251
- delete (p, name)
252
- save_project (proj. path, p)
253
258
end
254
259
255
260
# -------------------------------------------------------------------------------
0 commit comments