Handle /var/mqm/ permissions in upgrade to ubi (#316)
* handle /var/mqm/ permissions in upgrade to ubi
This commit is contained in:
@@ -24,6 +24,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/ibm-messaging/mq-container/internal/command"
|
||||
containerruntime "github.com/ibm-messaging/mq-container/internal/containerruntime"
|
||||
"github.com/ibm-messaging/mq-container/internal/mqscredact"
|
||||
@@ -41,6 +43,47 @@ func createDirStructure() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// configureOwnership recursively handles ownership of files within the given filepath
|
||||
func configureOwnership(paths []string) error {
|
||||
uid, gid, err := command.LookupMQM()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var fileInfo *unix.Stat_t
|
||||
fileInfo = new(unix.Stat_t)
|
||||
for _, root := range paths {
|
||||
_, err = os.Stat(root)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
err = filepath.Walk(root, func(from string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
to := fmt.Sprintf("%v%v", root, from[len(root):])
|
||||
err = unix.Stat(to, fileInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fileUID := fmt.Sprint(fileInfo.Uid)
|
||||
if strings.Compare(fileUID, "999") == 0 {
|
||||
err = os.Chown(to, uid, gid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// createQueueManager creates a queue manager, if it doesn't already exist.
|
||||
// It returns true if one was created (or a standby was created), or false if one already existed
|
||||
func createQueueManager(name string) (bool, error) {
|
||||
|
||||
Reference in New Issue
Block a user