@@ -174,23 +174,25 @@ func ShouldSendNotificationsToTheUser(st *state.State) (bool, error) {
174174 return true , nil
175175}
176176
177- func diskSpaceReservation (tr * config.Transaction ) uint64 {
177+ func diskSpaceReservation (tr * config.Transaction ) * uint64 {
178178 var reservation string
179179 err := tr .Get ("core" , "system.disk-space-reservation" , & reservation )
180180 if config .IsNoOption (err ) {
181181 // TODO: decide how unset system.disk-space-reservation should behave when
182182 // the experimental disk space feature flags are graduated.
183- return defaultDiskSpaceReservation
183+ defaultReservation := defaultDiskSpaceReservation
184+ return & defaultReservation
184185 }
185186 if err != nil {
186- return 0
187+ return nil
187188 }
188189
189190 parsedReservation , err := strutil .ParseByteSize (reservation )
190191 if err != nil {
191- return 0
192+ return nil
192193 }
193- return uint64 (parsedReservation )
194+ reservationBytes := uint64 (parsedReservation )
195+ return & reservationBytes
194196}
195197
196198// ConfigureSnap returns a set of tasks to configure snapName as done during installation/refresh.
@@ -2524,7 +2526,7 @@ func autoRefreshPhase2(st *state.State, candidates []*refreshCandidate, flags *F
25242526
25252527func checkDiskSpaceDownload (st * state.State , infos []minimalInstallInfo , rootDir string ) error {
25262528 reservation := diskSpaceReservation (config .NewTransaction (st ))
2527- if reservation == 0 {
2529+ if reservation == nil {
25282530 return nil
25292531 }
25302532
@@ -2533,7 +2535,7 @@ func checkDiskSpaceDownload(st *state.State, infos []minimalInstallInfo, rootDir
25332535 totalSize += uint64 (info .DownloadSize ())
25342536 }
25352537
2536- return checkForAvailableSpace (totalSize , reservation , infos , "download" , rootDir )
2538+ return checkForAvailableSpace (totalSize , * reservation , infos , "download" , rootDir )
25372539}
25382540
25392541// checkDiskSpace checks if there is enough space for the requested snaps and their prerequisites
@@ -2560,7 +2562,7 @@ func checkDiskSpace(st *state.State, changeKind string, infos []minimalInstallIn
25602562 }
25612563
25622564 reservation := diskSpaceReservation (tr )
2563- if reservation == 0 {
2565+ if reservation == nil {
25642566 return nil
25652567 }
25662568
@@ -2569,7 +2571,7 @@ func checkDiskSpace(st *state.State, changeKind string, infos []minimalInstallIn
25692571 return err
25702572 }
25712573
2572- return checkForAvailableSpace (totalSize , reservation , infos , changeKind , dirs .SnapdStateDir (dirs .GlobalRootDir ))
2574+ return checkForAvailableSpace (totalSize , * reservation , infos , changeKind , dirs .SnapdStateDir (dirs .GlobalRootDir ))
25732575}
25742576
25752577func checkForAvailableSpace (totalSize , reservation uint64 , infos []minimalInstallInfo , changeKind string , rootDir string ) error {
@@ -3171,11 +3173,11 @@ func Remove(st *state.State, name string, revision snap.Revision, flags *RemoveF
31713173 // will only be greater than 0 if the feature is enabled.
31723174 if snapshotSize > 0 {
31733175 reservation := diskSpaceReservation (config .NewTransaction (st ))
3174- if reservation == 0 {
3176+ if reservation == nil {
31753177 return ts , err
31763178 }
31773179
3178- requiredSpace := snapshotSize + reservation
3180+ requiredSpace := snapshotSize + * reservation
31793181 path := dirs .SnapdStateDir (dirs .GlobalRootDir )
31803182 if err := osutilCheckFreeSpace (path , requiredSpace ); err != nil {
31813183 if _ , ok := err .(* osutil.NotEnoughDiskSpaceError ); ok {
@@ -3327,7 +3329,7 @@ func removeTasks(st *state.State, snapst *SnapState, removals map[string]bool, r
33273329 if err != nil && ! config .IsNoOption (err ) {
33283330 return nil , 0 , err
33293331 }
3330- if checkDiskSpaceRemove && diskSpaceReservation (tr ) != 0 {
3332+ if checkDiskSpaceRemove && diskSpaceReservation (tr ) != nil {
33313333 snapshotSize , err = EstimateSnapshotSize (st , instanceName , nil )
33323334 if err != nil {
33333335 return nil , 0 , err
@@ -3611,11 +3613,11 @@ func RemoveMany(st *state.State, names []string, flags *RemoveFlags) ([]string,
36113613 // will only be greater than 0 if the feature is enabled.
36123614 if totalSnapshotsSize > 0 {
36133615 reservation := diskSpaceReservation (config .NewTransaction (st ))
3614- if reservation == 0 {
3616+ if reservation == nil {
36153617 return removed , tasksets , nil
36163618 }
36173619
3618- requiredSpace := totalSnapshotsSize + reservation
3620+ requiredSpace := totalSnapshotsSize + * reservation
36193621 if err := osutilCheckFreeSpace (path , requiredSpace ); err != nil {
36203622 if _ , ok := err .(* osutil.NotEnoughDiskSpaceError ); ok {
36213623 return nil , nil , & InsufficientSpaceError {
0 commit comments