From 4afcd4885d838e71fab67b56a92993ec72a63d9c Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 8 Dec 2022 12:05:02 -0800 Subject: [PATCH] feat: Use squashfuse_ll if available for faster squashfs. squashfuse README says of squashfuse_ll: Like `squashfuse`, but implemented using the low-level FUSE API. It's a tiny bit faster, but less portable. But some reports say things like "30x times faster." https://github.com/snapcore/snapd/pull/7477 Signed-off-by: Scott Moser --- squashfs/squashfs.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/squashfs/squashfs.go b/squashfs/squashfs.go index 17ded431..eb915d0b 100644 --- a/squashfs/squashfs.go +++ b/squashfs/squashfs.go @@ -168,21 +168,28 @@ func ExtractSingleSquash(squashFile string, extractDir string, storageType strin return err } - if p := which("squashfuse"); p != "" { + findSqfusePath := func() string { + if p := which("squashfuse_ll"); p != "" { + return p + } + return which("squashfuse") + } + + if sqfuse := findSqfusePath(); sqfuse != "" { // given extractDir of path/to/some/dir[/], log to path/to/some/.dir-squashfs.log extractDir := strings.TrimSuffix(extractDir, "/") var cmdOut io.Writer logf := path.Join(path.Dir(extractDir), "."+path.Base(extractDir)+"-squashfuse.log") if cmdOut, err = os.OpenFile(logf, os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0644); err != nil { - log.Infof("Failed to open %s for write: %v", p, err) + log.Infof("Failed to open %s for write: %v", logf, err) return err } // It would be nice to only enable debug (or maybe to only log to file at all) // if 'stacker --debug', but we do not have access to that info here. // to debug squashfuse, use "allow_other,debug" - cmd := exec.Command("squashfuse", "-f", "-o", "allow_other,debug", squashFile, extractDir) + cmd := exec.Command(sqfuse, "-f", "-o", "allow_other,debug", squashFile, extractDir) cmd.Stdin = nil cmd.Stdout = cmdOut cmd.Stderr = cmdOut