Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check whether symlink exists #534

Merged
merged 2 commits into from
Nov 10, 2023
Merged
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
34 changes: 31 additions & 3 deletions pkg/overlay/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@

// slight hack, but this is much faster than a cp, and the
// layers are the same, just in different formats
err = os.Symlink(overlayPath(config.RootFSDir, theLayer.Digest), overlayPath(config.RootFSDir, desc.Digest))
if err != nil {
return errors.Wrapf(err, "failed to create squashfs symlink")
if !PathExists(overlayPath(config.RootFSDir, desc.Digest)) {
err = os.Symlink(overlayPath(config.RootFSDir, theLayer.Digest), overlayPath(config.RootFSDir, desc.Digest))
if err != nil {
return errors.Wrapf(err, "failed to create squashfs symlink")
}

Check warning on line 158 in pkg/overlay/pack.go

View check run for this annotation

Codecov / codecov/patch

pkg/overlay/pack.go#L154-L158

Added lines #L154 - L158 were not covered by tests
}
newManifest.Layers = append(newManifest.Layers, desc)
newConfig.RootFS.DiffIDs = append(newConfig.RootFS.DiffIDs, desc.Digest)
Expand All @@ -167,6 +169,29 @@
return nil
}

func IsSymlink(path string) (bool, error) {
statInfo, err := os.Lstat(path)
if err != nil {
return false, err
}
return (statInfo.Mode() & os.ModeSymlink) != 0, nil

Check warning on line 177 in pkg/overlay/pack.go

View check run for this annotation

Codecov / codecov/patch

pkg/overlay/pack.go#L172-L177

Added lines #L172 - L177 were not covered by tests
}

func PathExists(path string) bool {
statInfo, err := os.Stat(path)
if statInfo == nil {
isLink, err := IsSymlink(path)
if err != nil {
return false
}
return isLink

Check warning on line 187 in pkg/overlay/pack.go

View check run for this annotation

Codecov / codecov/patch

pkg/overlay/pack.go#L180-L187

Added lines #L180 - L187 were not covered by tests
}
if err != nil && os.IsNotExist(err) {
return false
}
return true

Check warning on line 192 in pkg/overlay/pack.go

View check run for this annotation

Codecov / codecov/patch

pkg/overlay/pack.go#L189-L192

Added lines #L189 - L192 were not covered by tests
}

func lookupManifestInDir(dir, name string) (ispec.Manifest, error) {
oci, err := umoci.OpenLayout(dir)
if err != nil {
Expand Down Expand Up @@ -372,6 +397,9 @@
if ovl.HasBuiltOCIOutput {
for i, layerType := range layerTypes {
manifest := ovl.Manifests[layerType]
if len(manifest.Layers) < 1 {
continue

Check warning on line 401 in pkg/overlay/pack.go

View check run for this annotation

Codecov / codecov/patch

pkg/overlay/pack.go#L400-L401

Added lines #L400 - L401 were not covered by tests
}
layer := manifest.Layers[len(manifest.Layers)-1]

config := ovl.Configs[layerType]
Expand Down
Loading