From 014563fdbcd22122e12f9ed63b67111e5c801f96 Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Thu, 23 May 2024 17:05:39 -0700 Subject: [PATCH] osutil: add function to detect merged /usr systems (MR 39) This is very crude, but in lieu of an actual spec for usr merge or some standard way to detect whether it's done, this will have to do for now. We can and should improve it later! --- internal/osutil/osutil.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/internal/osutil/osutil.go b/internal/osutil/osutil.go index 279bd00..85ec867 100644 --- a/internal/osutil/osutil.go +++ b/internal/osutil/osutil.go @@ -10,6 +10,23 @@ import ( "golang.org/x/sys/unix" ) +// Try to guess whether the system has merged dirs under /usr +func HasMergedUsr() bool { + for _, dir := range []string{"/bin", "/lib"} { + stat, err := os.Lstat(dir) + if err != nil { + // TODO: probably because the dir doesn't exist... so + // should we assume that it's because the system has some weird + // implementation of "merge /usr"? + return true + } else if stat.Mode()&os.ModeSymlink == 0 { + // Not a symlink, so must not be merged /usr + return false + } + } + return true +} + // Converts a relative symlink target path (e.g. ../../lib/foo.so), that is // absolute path func RelativeSymlinkTargetToDir(symPath string, dir string) (string, error) {