1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
// Copyright (c) 2021-2022, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package siftool
import (
"os"
"github.com/sylabs/sif/v2/pkg/sif"
)
// withFileImage calls fn with a FileImage loaded from path.
func withFileImage(path string, writable bool, fn func(*sif.FileImage) error) error {
flag := os.O_RDONLY
if writable {
flag = os.O_RDWR
}
f, err := sif.LoadContainerFromPath(path, sif.OptLoadWithFlag(flag))
if err != nil {
return err
}
err = fn(f)
if uerr := f.UnloadContainer(); err == nil {
err = uerr
}
return err
}
|