@@ -197,45 +197,68 @@ func (d *archiveFileResource) Create(ctx context.Context, req resource.CreateReq
197
197
return
198
198
}
199
199
200
+ resp .Diagnostics .Append (updateModel (ctx , & model )... )
201
+
202
+ diags = resp .State .Set (ctx , model )
203
+ resp .Diagnostics .Append (diags ... )
204
+ }
205
+
206
+ func (d * archiveFileResource ) Read (ctx context.Context , req resource.ReadRequest , resp * resource.ReadResponse ) {
207
+ var model fileModel
208
+ diags := req .State .Get (ctx , & model )
209
+ resp .Diagnostics .Append (diags ... )
210
+ if resp .Diagnostics .HasError () {
211
+ return
212
+ }
213
+
214
+ resp .Diagnostics .Append (updateModel (ctx , & model )... )
215
+
216
+ diags = resp .State .Set (ctx , model )
217
+ resp .Diagnostics .Append (diags ... )
218
+ }
219
+
220
+ func updateModel (ctx context.Context , model * fileModel ) diag.Diagnostics {
221
+ var diags diag.Diagnostics
200
222
outputPath := model .OutputPath .ValueString ()
201
223
202
224
outputDirectory := path .Dir (outputPath )
203
225
if outputDirectory != "" {
204
226
if _ , err := os .Stat (outputDirectory ); err != nil {
205
227
if err := os .MkdirAll (outputDirectory , 0755 ); err != nil {
206
- resp . Diagnostics .AddError (
228
+ diags .AddError (
207
229
"Output path error" ,
208
230
fmt .Sprintf ("error creating output path: %s" , err ),
209
231
)
210
- return
232
+ return diags
211
233
}
212
234
}
213
235
}
214
236
215
- if err := archive (ctx , model ); err != nil {
216
- resp . Diagnostics .AddError (
237
+ if err := archive (ctx , * model ); err != nil {
238
+ diags .AddError (
217
239
"Archive creation error" ,
218
240
fmt .Sprintf ("error creating archive: %s" , err ),
219
241
)
220
- return
242
+ return diags
221
243
}
222
244
223
245
// Generate archived file stats
224
246
fi , err := os .Stat (outputPath )
225
247
if err != nil {
226
- resp . Diagnostics .AddError (
248
+ diags .AddError (
227
249
"Archive output error" ,
228
250
fmt .Sprintf ("error reading output: %s" , err ),
229
251
)
230
- return
252
+ return diags
231
253
}
232
254
233
255
sha1 , base64sha256 , md5 , err := genFileShas (outputPath )
234
256
if err != nil {
235
- resp . Diagnostics .AddError (
257
+ diags .AddError (
236
258
"Hash generation error" ,
237
259
fmt .Sprintf ("error generating hashed: %s" , err ),
238
260
)
261
+ return diags
239
262
}
240
263
241
264
model .OutputSha = types .StringValue (sha1 )
@@ -245,11 +268,7 @@ func (d *archiveFileResource) Create(ctx context.Context, req resource.CreateReq
245
268
246
269
model .ID = types .StringValue (sha1 )
247
270
248
- diags = resp .State .Set (ctx , model )
249
- resp .Diagnostics .Append (diags ... )
250
- }
251
-
252
- func (d * archiveFileResource ) Read (_ context.Context , _ resource.ReadRequest , _ * resource.ReadResponse ) {
271
+ return diags
253
272
}
254
273
255
274
func (d * archiveFileResource ) Update (_ context.Context , _ resource.UpdateRequest , _ * resource.UpdateResponse ) {
0 commit comments