Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions toolkit/tools/internal/buildpipeline/buildpipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,30 +179,38 @@ func GetRpmsDir(chrootDir string, proposedDir string) string {
return filepath.Join(chrootDir, "localrpms")
}

// CleanupDockerChroot: Docker based only, clean chroot => delete everything but the folders listed
// CleanupDockerChroot: Docker based only, clean chroot =>
// 1) delete everything but the folders listed
// these folders are the ones mounted in docker run command (-v option)
// 2) create empty folders
// these folders are required by chroot (e.g.: /run) and needs to be created empty
// to not inherit anything from previous build
func CleanupDockerChroot(chroot string) (err error) {
var folderToKeep = []string{
"dev",
"proc",
"run",
"localrpms",
"upstream-cached-rpms",
"sys",
chrootUse,
}

var folderToCreate = []string{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: folders since it's an array

"run",
}

logger.Log.Debugf("cleanup Chroot -> %s", chroot)

rootFolder, err := os.Open(chroot)
if err != nil {
logger.Log.Warnf("Open chroot %s failed - %v", chroot, err)
logger.Log.Warnf("Open chroot %s failed - %s", chroot, err)
return err
}

defer rootFolder.Close()
names, err := rootFolder.Readdirnames(-1)
if err != nil {
logger.Log.Warnf("Reading files and folders under chroot %s failed - %v", chroot, err)
logger.Log.Warnf("Reading files and folders under chroot %s failed - %s", chroot, err)
return err
}

Expand All @@ -217,10 +225,18 @@ func CleanupDockerChroot(chroot string) (err error) {
if toDelete {
err = os.RemoveAll(filepath.Join(chroot, name))
if err != nil {
logger.Log.Warnf("Removing files in chroot %s failed: %v", chroot, err)
logger.Log.Warnf("Removing files in chroot %s failed: %s", chroot, err)
}
}
}

// create some folder(s) once chroot has been cleaned up
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you extend the comment to explain why we want to create new folders during clean-up? I'm actually curious myself.

for _, folder := range folderToCreate {
err = os.Mkdir(filepath.Join(chroot, folder), os.ModePerm)
if err != nil {
logger.Log.Warnf("Creation of %s folder in chroot %s failed: %s", folder, chroot, err)
}
}

return
}