From a2455747be2fa790a5e17bcd51cacf15eba4edb4 Mon Sep 17 00:00:00 2001 From: preminger Date: Tue, 30 May 2023 10:39:46 -0400 Subject: [PATCH] more robust way of setting IFS to newline (#1708) * more robust way of setting IFS to newline * e2e test for issue 1704 * added bugfix info to changelog --- CHANGELOG.md | 2 ++ cmd/internal/cli/inspect.go | 3 ++- e2e/docker/docker.go | 3 ++- e2e/docker/regressions.go | 43 +++++++++++++++++++++++++++++++++++++ test/defs/issue1704.def | 10 +++++++++ 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 test/defs/issue1704.def diff --git a/CHANGELOG.md b/CHANGELOG.md index d0620a7b25..33ac40eb13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,8 @@ ### Bug Fixes - Fix interaction between `--workdir` when given relative path and `--scratch`. +- Fix dropped "n" characters on some platforms in definition file stored as part + of SIF metadata. ## 3.11.3 \[2023-05-04\] diff --git a/cmd/internal/cli/inspect.go b/cmd/internal/cli/inspect.go index 649995c319..243547c359 100644 --- a/cmd/internal/cli/inspect.go +++ b/cmd/internal/cli/inspect.go @@ -242,7 +242,8 @@ func newCommand(allData bool, appName string, img *image.Image) *command { cat_file() { echo "%[3]s $1:$2" - local IFS=$'\n' + local IFS=" +" while read -r content; do printf "%%s\n" "$content" done < "$2" diff --git a/e2e/docker/docker.go b/e2e/docker/docker.go index 2ada7a0cc6..1ee53d016a 100644 --- a/e2e/docker/docker.go +++ b/e2e/docker/docker.go @@ -1037,6 +1037,7 @@ func E2ETests(env e2e.TestEnv) testhelper.Tests { // Regressions "issue 4943": c.issue4943, "issue 5172": c.issue5172, - "issue 274": c.issue274, // https://github.com/sylabs/singularity/issues/274 + "issue 274": c.issue274, // https://github.com/sylabs/singularity/issues/274 + "issue 1704": c.issue1704, // https://github.com/sylabs/singularity/issues/1704 } } diff --git a/e2e/docker/regressions.go b/e2e/docker/regressions.go index 885f19879d..26518367c4 100644 --- a/e2e/docker/regressions.go +++ b/e2e/docker/regressions.go @@ -12,6 +12,7 @@ import ( "os" "path" "path/filepath" + "strings" "testing" "github.com/sylabs/singularity/e2e/internal/e2e" @@ -182,6 +183,48 @@ From: continuumio/miniconda3:latest ) } +// https://github.com/sylabs/singularity/issues/1704 Ensure that trailing "n"s +// aren't lopped off by the internal sandbox inspect call that is part of the +// SIF-building process. +func (c ctx) issue1704(t *testing.T) { + tmpDir, cleanup := e2e.MakeTempDir(t, c.env.TestDir, "issue1704-", "") + t.Cleanup(func() { + if !t.Failed() { + cleanup(t) + } + }) + + defPath := filepath.Join("..", "test", "defs", "issue1704.def") + sifPath := filepath.Join(tmpDir, "issue1704.sif") + bytes, err := os.ReadFile(defPath) + if err != nil { + t.Fatalf("could not read contents of def file %q: %s", defPath, err) + } + defFileContents := string(bytes) + + c.env.RunSingularity( + t, + e2e.AsSubtest("Build"), + e2e.WithProfile(e2e.RootProfile), + e2e.WithCommand("build"), + e2e.WithArgs(sifPath, defPath), + e2e.ExpectExit(0), + ) + + if t.Failed() { + return + } + + c.env.RunSingularity( + t, + e2e.AsSubtest("Inspect"), + e2e.WithProfile(e2e.UserProfile), + e2e.WithCommand("inspect"), + e2e.WithArgs("-d", sifPath), + e2e.ExpectExit(0, e2e.ExpectOutput(e2e.ContainMatch, strings.TrimSpace(defFileContents))), + ) +} + // https://github.com/sylabs/singularity/issues/1286 // Ensure the bare docker://hello-world image runs in all modes func (c ctx) issue1286(t *testing.T) { diff --git a/test/defs/issue1704.def b/test/defs/issue1704.def new file mode 100644 index 0000000000..f7f90403fb --- /dev/null +++ b/test/defs/issue1704.def @@ -0,0 +1,10 @@ +BootStrap: docker +From: ubuntu:22.04 + +%setup + #an + #abn + #nn + #ann + #nan + #anan