Skip to content

Add PutOptions.AttemptUnpackDockerCompatibility - #7010

Open
ajoshua2004 wants to merge 1 commit into
podman-container-tools:mainfrom
ajoshua2004:unpackDocker
Open

Add PutOptions.AttemptUnpackDockerCompatibility#7010
ajoshua2004 wants to merge 1 commit into
podman-container-tools:mainfrom
ajoshua2004:unpackDocker

Conversation

@ajoshua2004

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind api-change

What this PR does / why we need it:

Adds AttemptUnpackDockerCompatibility (bool) to copier.PutOptions. When enabled, the Put handler detects if a written regular file is a possibly-compressed archive (gzip/bzip2/xz/zstd) and extracts its contents in place instead of keeping the archive as-is.

How to verify it

go test ./copier/ -run TestAttemptUnpackDockerCompatibilityNoChroot -v
go test ./copier/ -run TestAttemptUnpackDockerCompatibilityChroot -v

Which issue(s) this PR fixes:

Part of #6732

Special notes for your reviewer:

The detection reuses the existing isArchivePath() and compression.AutoDecompress() infrastructure already used on the Get side for ExpandArchives. The flag is not wired to any caller yet, it's available on PutOptions for callers to opt into when needed.

Does this PR introduce a user-facing change?

None
Comment thread copier/copier.go Outdated
f.Close()
return fmt.Errorf("copier: put: error reading unpacked archive %q: %w", path, err)
}
entryPath := filepath.Join(destDir, entry.Name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@nalind is this safe? Could it write outside of it's destination?

Comment thread copier/copier.go Outdated
if err := ensureDirectoryUnderRoot(filepath.Dir(entryPath)); err != nil {
rc.Close()
f.Close()
return fmt.Errorf("copier: Invalid path: %v", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("copier: Invalid path: %v", err)
return fmt.Errorf("copier: put: Invalid path: %v", err)
Comment thread copier/copier_unix_test.go Outdated
t.Skip("chroot() requires root privileges, skipping")
}
couldChroot := canChroot
canChroot = false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be here, true?

Comment thread copier/copier.go
Comment on lines +2231 to +2232
rc.Close()
f.Close()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not use defer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

defer here wouldn't be safe because this runs in a per header loop and the way success path ends is with the goto nextHeader rather than return so they would skip the defered runs

Detect if written files are possibly compressed archives during Put and extract them
instead of copying them when the flag is set.

Signed-off-by: Joshua Arrevillaga <2004jarrevillaga@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants