Skip to content

Commit

Permalink
feat: volume copy src dir fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wozniakjan committed Mar 14, 2023
1 parent 61a6301 commit 910ee3c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/nfs/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ func (cs *ControllerServer) copyFromVolume(ctx context.Context, req *csi.CreateV
if err != nil {
return status.Error(codes.NotFound, err.Error())
}
srcPath := getInternalVolumePath(cs.Driver.workingMountDir, srcVol)
// Note that the source path must include trailing '/.', can't use 'filepath.Join()' as it performs path cleaning
srcPath := fmt.Sprintf("%v/.", getInternalVolumePath(cs.Driver.workingMountDir, srcVol))
dstPath := getInternalVolumePath(cs.Driver.workingMountDir, dstVol)
klog.V(2).Infof("copy volume from volume %v -> %v", srcPath, dstPath)

Expand All @@ -345,13 +346,12 @@ func (cs *ControllerServer) copyFromVolume(ctx context.Context, req *csi.CreateV
}
}()

// recursive 'cp' with '-a' to handle symlinks. Note that the source path must include trailing '/.',
// which is the reason why 'filepath.Join()' is not used as it would perform path cleaning
out, err := exec.Command("cp", "-a", fmt.Sprintf("%v%v.", srcPath, filepath.Separator), dstPath).CombinedOutput()
klog.V(2).Infof("copied %s -> %s output: %v", srcPath, dstPath, string(out))
// recursive 'cp' with '-a' to handle symlinks
out, err := exec.Command("cp", "-a", srcPath, dstPath).CombinedOutput()
if err != nil {
return status.Error(codes.Internal, err.Error())
return status.Error(codes.Internal, fmt.Sprintf("%v: %v", err, string(out)))
}
klog.V(2).Infof("copied %s -> %s output: %v", srcPath, dstPath)
return nil
}

Expand Down

0 comments on commit 910ee3c

Please sign in to comment.