@@ -277,6 +277,62 @@ func (k msgServer) UpdateRepositoryPackfile(goCtx context.Context, msg *types.Ms
277277 return & types.MsgUpdateRepositoryPackfileResponse {}, nil
278278}
279279
280+ func (k msgServer ) DeleteRepositoryPackfile (goCtx context.Context , msg * types.MsgDeleteRepositoryPackfile ) (* types.MsgDeleteRepositoryPackfileResponse , error ) {
281+ ctx := sdk .UnwrapSDKContext (goCtx )
282+
283+ // Check if provider is active
284+ provider , found := k .GetProvider (ctx , msg .Creator )
285+ if ! found || provider .Status != types .ProviderStatus_PROVIDER_STATUS_ACTIVE {
286+ return nil , fmt .Errorf ("provider is not active" )
287+ }
288+
289+ repository , found := k .gitopiaKeeper .GetRepositoryById (ctx , msg .RepositoryId )
290+ if ! found {
291+ return nil , fmt .Errorf ("repository not found" )
292+ }
293+
294+ userQuota , found := k .gitopiaKeeper .GetUserQuota (ctx , repository .Owner .Id )
295+ if ! found {
296+ // Create new user quota
297+ userQuota = gitopiatypes.UserQuota {
298+ Address : repository .Owner .Id ,
299+ StorageUsed : 0 ,
300+ }
301+ }
302+
303+ // Check if packfile exists for this repository
304+ packfile , found := k .GetPackfile (ctx , msg .RepositoryId )
305+ if ! found {
306+ return nil , fmt .Errorf ("packfile not found" )
307+ }
308+
309+ // Decrement or remove old cid reference count
310+ if packfile .Cid != "" {
311+ k .DecreaseCidReferenceCount (ctx , packfile .Cid )
312+ if count , found := k .GetCidReferenceCount (ctx , packfile .Cid ); found && count .Count == 0 {
313+ k .RemoveCidReferenceCount (ctx , packfile .Cid )
314+ }
315+ }
316+
317+ userQuota .StorageUsed -= uint64 (packfile .Size_ )
318+ k .gitopiaKeeper .SetUserQuota (ctx , userQuota )
319+
320+ // Remove existing packfile
321+ k .RemovePackfile (ctx , msg .RepositoryId )
322+
323+ // Update total storage size
324+ k .SetTotalStorageSize (ctx , k .GetTotalStorageSize (ctx )- uint64 (packfile .Size_ ))
325+
326+ // Emit event
327+ ctx .EventManager ().EmitTypedEvent (& types.EventPackfileDeleted {
328+ RepositoryId : msg .RepositoryId ,
329+ Name : packfile .Name ,
330+ Cid : packfile .Cid ,
331+ })
332+
333+ return & types.MsgDeleteRepositoryPackfileResponse {}, nil
334+ }
335+
280336func (k msgServer ) UpdateReleaseAsset (goCtx context.Context , msg * types.MsgUpdateReleaseAsset ) (* types.MsgUpdateReleaseAssetResponse , error ) {
281337 ctx := sdk .UnwrapSDKContext (goCtx )
282338
0 commit comments