@@ -44,7 +44,8 @@ type ChrootEnvInterface interface {
4444 UmountChrootPath (chrootPath string ) error
4545 CopyFileFromHostToChroot (hostFilePath , chrootPath string ) error
4646 CopyFileFromChrootToHost (hostFilePath , chrootPath string ) error
47- RefreshLocalCacheRepo (targetArch string ) error
47+ UpdateChrootLocalRepoMetadata (chrootRepoDir string , targetArch string , sudo bool ) error
48+ RefreshLocalCacheRepo () error
4849 InitChrootEnv (targetOs , targetDist , targetArch string ) error
4950 CleanupChrootEnv (targetOs , targetDist , targetArch string ) error
5051 TdnfInstallPackage (packageName , installRoot string , repositoryIDList []string ) error
@@ -248,29 +249,40 @@ func (chrootEnv *ChrootEnv) updateChrootLocalRPMRepo(chrootRepoDir string) error
248249 return nil
249250}
250251
251- func (chrootEnv * ChrootEnv ) updateChrootLocalDebRepo (chrootPkgCacheDir , targetArch string ) error {
252- return chrootEnv .ChrootBuilder .UpdateLocalDebRepo (chrootPkgCacheDir , targetArch )
252+ func (chrootEnv * ChrootEnv ) updateChrootLocalDebRepo (chrootPkgCacheDir , targetArch string , sudo bool ) error {
253+ return chrootEnv .ChrootBuilder .UpdateLocalDebRepo (chrootPkgCacheDir , targetArch , sudo )
253254}
254255
255- func (chrootEnv * ChrootEnv ) RefreshLocalCacheRepo (targetArch string ) error {
256- // From local.repo
256+ func (chrootEnv * ChrootEnv ) UpdateChrootLocalRepoMetadata (chrootRepoDir string , targetArch string , sudo bool ) error {
257257 pkgType := chrootEnv .GetTargetOsPkgType ()
258258 if pkgType == "rpm" {
259- releaseVersion := chrootEnv .GetTargetOsReleaseVersion ()
260- if err := chrootEnv .updateChrootLocalRPMRepo (ChrootRepoDir ); err != nil {
261- return fmt .Errorf ("failed to update rpm local cache repository %s: %w" , ChrootRepoDir , err )
259+ if err := chrootEnv .updateChrootLocalRPMRepo (chrootRepoDir ); err != nil {
260+ return fmt .Errorf ("failed to update rpm local cache repository %s: %w" , chrootRepoDir , err )
261+ }
262+ } else if pkgType == "deb" {
263+ chrootPkgCacheDir , err := chrootEnv .GetChrootEnvHostPath (chrootRepoDir )
264+ if err != nil {
265+ return fmt .Errorf ("failed to get chroot host path for %s: %w" , chrootRepoDir , err )
266+ }
267+ if err := chrootEnv .updateChrootLocalDebRepo (chrootPkgCacheDir , targetArch , sudo ); err != nil {
268+ return fmt .Errorf ("failed to update debian local cache repository: %v" , err )
262269 }
270+ } else {
271+ return fmt .Errorf ("unsupported package type: %s" , pkgType )
272+ }
273+ return nil
274+ }
263275
276+ func (chrootEnv * ChrootEnv ) RefreshLocalCacheRepo () error {
277+ // From local.repo
278+ pkgType := chrootEnv .GetTargetOsPkgType ()
279+ if pkgType == "rpm" {
280+ releaseVersion := chrootEnv .GetTargetOsReleaseVersion ()
264281 cmd := fmt .Sprintf ("tdnf makecache --releasever %s" , releaseVersion )
265282 if _ , err := shell .ExecCmdWithStream (cmd , true , chrootEnv .ChrootEnvRoot , nil ); err != nil {
266283 return fmt .Errorf ("failed to refresh cache for chroot repository: %w" , err )
267284 }
268285 } else if pkgType == "deb" {
269- chrootPkgCacheDir := chrootEnv .GetChrootPkgCacheDir ()
270- if err := chrootEnv .updateChrootLocalDebRepo (chrootPkgCacheDir , targetArch ); err != nil {
271- return fmt .Errorf ("failed to update debian local cache repository: %v" , err )
272- }
273-
274286 cmd := "apt clean"
275287 if _ , err := shell .ExecCmdWithStream (cmd , true , chrootEnv .ChrootEnvRoot , nil ); err != nil {
276288 return fmt .Errorf ("failed to clean cache for chroot repository: %w" , err )
@@ -293,7 +305,15 @@ func (chrootEnv *ChrootEnv) initChrootLocalRepo(targetArch string) error {
293305 chrootPkgCacheDir , ChrootRepoDir , err )
294306 }
295307
296- if err := chrootEnv .RefreshLocalCacheRepo (targetArch ); err != nil {
308+ if chrootEnv .ChrootEnvRoot != shell .HostPath {
309+ // Within iso initramfs system, local repo metadata should have been generated
310+ // And the repo cache is read-only, not able to update by live-installer
311+ if err := chrootEnv .UpdateChrootLocalRepoMetadata (ChrootRepoDir , targetArch , false ); err != nil {
312+ return fmt .Errorf ("failed to update chroot local cache repository metadata: %w" , err )
313+ }
314+ }
315+
316+ if err := chrootEnv .RefreshLocalCacheRepo (); err != nil {
297317 return fmt .Errorf ("failed to refresh local cache repository: %w" , err )
298318 }
299319 return nil
0 commit comments