@@ -3774,37 +3774,56 @@ let put_bundle_handler (req : Request.t) s _ =
3774
3774
~doc: " pool.sync_bundle" ~op: `sync_bundle
3775
3775
@@ fun () ->
3776
3776
Http_svr. headers s (Http. http_200_ok () ) ;
3777
- let repo =
3778
- Repository_helpers. get_single_enabled_update_repository ~__context
3779
- in
3780
- match Db.Repository. get_origin ~__context ~self: repo with
3781
- | `bundle -> (
3782
- let result =
3783
- Tar_ext. unpack_tar_file
3784
- ~dir: ! Xapi_globs. bundle_repository_dir
3785
- ~ifd: s
3786
- ~max_size_limit: ! Xapi_globs. bundle_max_size_limit
3777
+ let repo_opt =
3778
+ try
3779
+ let repo =
3780
+ Repository_helpers. get_single_enabled_update_repository ~__context
3787
3781
in
3788
- match result with
3789
- | Ok () ->
3790
- TaskHelper. set_progress ~__context 0.8 ;
3791
- finally
3792
- (fun () ->
3793
- sync_repos ~__context ~self: pool ~repos: [repo] ~force: true
3794
- ~token: " " ~token_id: " "
3795
- |> ignore
3796
- )
3797
- (fun () -> Unixext. rm_rec ! Xapi_globs. bundle_repository_dir)
3798
- | Error e ->
3799
- error " %s: Failed to unpack bundle with error %s" __FUNCTION__
3800
- (Tar_ext. unpack_error_to_string e) ;
3801
- TaskHelper. failed ~__context
3802
- Api_errors. (
3803
- Server_error
3804
- (bundle_unpack_failed, [Tar_ext. unpack_error_to_string e])
3805
- ) ;
3806
- Http_svr. headers s (Http. http_400_badrequest () )
3807
- )
3808
- | `remote ->
3809
- raise Api_errors. (Server_error (bundle_repo_not_enabled, [] ))
3782
+ Some repo
3783
+ with e ->
3784
+ TaskHelper. failed ~__context e ;
3785
+ Http_svr. headers s (Http. http_400_badrequest () ) ;
3786
+ None
3787
+ in
3788
+ match repo_opt with
3789
+ | Some repo -> (
3790
+ match Db.Repository. get_origin ~__context ~self: repo with
3791
+ | `bundle -> (
3792
+ let result =
3793
+ Tar_ext. unpack_tar_file
3794
+ ~dir: ! Xapi_globs. bundle_repository_dir
3795
+ ~ifd: s
3796
+ ~max_size_limit: ! Xapi_globs. bundle_max_size_limit
3797
+ in
3798
+ match result with
3799
+ | Ok () ->
3800
+ TaskHelper. set_progress ~__context 0.8 ;
3801
+ finally
3802
+ (fun () ->
3803
+ try
3804
+ sync_repos ~__context ~self: pool ~repos: [repo] ~force: true
3805
+ ~token: " " ~token_id: " "
3806
+ |> ignore
3807
+ with _ ->
3808
+ raise Api_errors. (Server_error (bundle_sync_failed, [] ))
3809
+ )
3810
+ (fun () -> Unixext. rm_rec ! Xapi_globs. bundle_repository_dir)
3811
+ | Error e ->
3812
+ error " %s: Failed to unpack bundle with error %s" __FUNCTION__
3813
+ (Tar_ext. unpack_error_to_string e) ;
3814
+ TaskHelper. failed ~__context
3815
+ Api_errors. (
3816
+ Server_error
3817
+ (bundle_unpack_failed, [Tar_ext. unpack_error_to_string e])
3818
+ ) ;
3819
+ Http_svr. headers s (Http. http_400_badrequest () )
3820
+ )
3821
+ | `remote ->
3822
+ error " %s: Bundle repo is not enabled" __FUNCTION__ ;
3823
+ TaskHelper. failed ~__context
3824
+ Api_errors. (Server_error (bundle_repo_not_enabled, [] )) ;
3825
+ Http_svr. headers s (Http. http_400_badrequest () )
3826
+ )
3827
+ | None ->
3828
+ ()
3810
3829
)
0 commit comments