Use a sentinel file to determine container readonly state. #1447

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2024-11-24 21:08:01 -07:00
parent 470fb323eb
commit 07f6402520
5 changed files with 18 additions and 19 deletions

View File

@@ -120,7 +120,7 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
}
ps1Str = fmt.Sprintf("[%s|ro|%s] Warewulf> ", containerName, nodename)
}
if !util.IsWriteAble(containerPath) && nodename == "" {
if !container.IsWriteAble(containerName) && nodename == "" {
wwlog.Verbose("mounting %s ro", containerPath)
ps1Str = fmt.Sprintf("[%s|ro] Warewulf> ", containerName)
err = syscall.Mount(containerPath, containerPath, "", syscall.MS_BIND, "")

View File

@@ -2,6 +2,7 @@ package container
import (
"os"
"path/filepath"
"github.com/pkg/errors"
@@ -109,3 +110,7 @@ func DeleteImage(name string) error {
}
return errors.Errorf("Image %s of container %s doesn't exist\n", imageFile, name)
}
func IsWriteAble(name string) bool {
return !util.IsFile(filepath.Join(SourceDir(name), "readonly"))
}

View File

@@ -565,21 +565,3 @@ func ByteToString(b int64) string {
}
return fmt.Sprintf("%.1f %ciB", float64(b)/float64(div), "KMGTPE"[exp])
}
/*
Check if the w-bit of a file/dir. unix.Access(file,unix.W_OK) will
not show this.
*/
func IsWriteAble(path string) bool {
info, err := os.Stat(path)
if err != nil {
return false
}
// Check if the user bit is enabled in file permission
if info.Mode().Perm()&(1<<(uint(7))) == 0 {
wwlog.Debug("Write permission bit is not set for: %s", path)
return false
}
return true
}