Skip to content

Commit

Permalink
fix!: copy contents of directory instead of the directory if store is…
Browse files Browse the repository at this point in the history
… used for directories (#2326)

Closes #2227
  • Loading branch information
h4ck3rk3y committed Apr 29, 2024
1 parent 989aad2 commit 4c776be
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
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
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
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

0 comments on commit 4c776be

Please sign in to comment.