Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/bpm/runc/adapter/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package adapter

import (
"path/filepath"
"sort"
"strings"

Expand All @@ -34,9 +35,15 @@ func Mount(from, to string, opts ...MountOption) specs.Mount {
opt(mountOpts)
}

// Resolve symlinks in source path for Noble stemcell compatibility
resolvedFrom := from
if resolved, err := filepath.EvalSymlinks(from); err == nil {
resolvedFrom = resolved
}

return specs.Mount{
Destination: to,
Source: from,
Source: resolvedFrom,
Type: "bind",
Options: mountOpts.opts(),
}
Expand Down
95 changes: 95 additions & 0 deletions src/bpm/runc/adapter/mount_symlink_test.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this can probably be src/bpm/runc/adapter/mount_test.go since there are unlikely to be more mount_{xyz}_test.go files.

Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (C) 2026-Present CloudFoundry.org Foundation, Inc. All rights reserved.
//
// This program and the accompanying materials are made available under
// the terms of the under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.

package adapter_test

import (
"os"
"path/filepath"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

. "bpm/runc/adapter"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: generally try to avoid dot-imports (ginkgo / gomega being an exception)

)

var _ = Describe("Mount with Symlink Resolution", func() {
var (
tempDir string
realDir string
symlinkPath string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: to better reveal intention perhaps this var could be symlinkToRealDir?

)

BeforeEach(func() {
var err error
tempDir, err = os.MkdirTemp("", "bpm-mount-test")
Expect(err).NotTo(HaveOccurred())

realDir = filepath.Join(tempDir, "real-directory")
err = os.Mkdir(realDir, 0755)
Expect(err).NotTo(HaveOccurred())

symlinkPath = filepath.Join(tempDir, "symlink")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: similar to the var naming, this value could be "symlink-to-real-directory"

err = os.Symlink(realDir, symlinkPath)
Expect(err).NotTo(HaveOccurred())
})

AfterEach(func() {
err := os.RemoveAll(tempDir)
Expect(err).NotTo(HaveOccurred())
})

Context("when mounting a symlinked path", func() {
It("resolves the symlink to the real path", func() {
mount := Mount(symlinkPath, "/container/path")

Expect(mount.Source).To(Equal(realDir))
Expect(mount.Destination).To(Equal("/container/path"))
Expect(mount.Type).To(Equal("bind"))
})
})

Context("when mounting a non-symlinked path", func() {
It("uses the path as-is", func() {
mount := Mount(realDir, "/container/path")

Expect(mount.Source).To(Equal(realDir))
Expect(mount.Destination).To(Equal("/container/path"))
Expect(mount.Type).To(Equal("bind"))
})
})

Context("when the symlink path does not exist", func() {
It("uses the original path", func() {
nonExistentPath := filepath.Join(tempDir, "does-not-exist")
mount := Mount(nonExistentPath, "/container/path")

Expect(mount.Source).To(Equal(nonExistentPath))
Expect(mount.Destination).To(Equal("/container/path"))
})
})

Context("with IdentityMount", func() {
It("resolves symlinks in both source and destination", func() {
mount := IdentityMount(symlinkPath)

// Source should be resolved, but destination stays as-is
// because IdentityMount(path) calls Mount(path, path)
// and the destination is not resolved
Expect(mount.Source).To(Equal(realDir))
Expect(mount.Destination).To(Equal(symlinkPath))
})
})
})
Loading