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

fix!: copy contents of directory instead of the directory if store is used for directories #2326

Merged
merged 9 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,20 @@ func (manager *DockerManager) CreateContainerExec(context context.Context, conta
// The caller must close the result
func (manager *DockerManager) CopyFromContainer(ctx context.Context, containerId string, srcPath string) (io.ReadCloser, error) {

stat, err := manager.dockerClient.ContainerStatPath(ctx, containerId, srcPath)
if err != nil {
return nil, stacktrace.Propagate(err, "an error occurred while verifying whether the file was a folder")
}

// if it's a directory we copy contents of the directory
if stat.Mode.IsDir() && !strings.HasSuffix(srcPath, "/.") {
if strings.HasSuffix(srcPath, "/") {
srcPath = srcPath + "."
} else {
srcPath = srcPath + "/."
}
}

tarStreamReadCloser, _, err := manager.dockerClient.CopyFromContainer(
ctx,
containerId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const (
ignoreParentDirInArchiveSymbol = "."
)

var commandString = `if command -v 'tar' > /dev/null; then cd '%v' && tar cf - '%v'; else echo "Cannot copy files from path '%v' because the tar binary doesn't exist on the machine" >&2; exit 1; fi`
// tries to copy contents of dir and if not dir reverts to default copy
var commandString = `if command -v 'tar' > /dev/null; then cd '%v' && (tar cf - -C '%v' . || tar cf - '%v'); else echo "Cannot copy files from path '%v' because the tar binary doesn't exist on the machine" >&2; exit 1; fi`

func CopyFilesFromUserService(
ctx context.Context,
Expand Down Expand Up @@ -76,6 +77,7 @@ func CopyFilesFromUserService(
commandString,
srcPathDir,
srcPathBase,
srcPathBase,
srcPath,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def run(plan):
file_artifacts = result.files_artifacts
result2 = plan.run_sh(run="cat /temp/tech.txt", files={"/temp": file_artifacts[0]})
plan.verify(result2.output, "==", "kurtosis\n")
result3 = plan.run_sh(run="cat /task/src/tech.txt", files={"/task": file_artifacts[1]})
result3 = plan.run_sh(run="cat /task/tech.txt", files={"/task": file_artifacts[1]})
plan.verify(result3.output, "==", "kurtosis\n")
result4 = plan.run_sh(run = "cat /task/example.txt", files={"/task": file_artifacts[2]})
plan.verify(result4.output, "==", "example\n")
Expand Down