Skip to content

Commit 910ee3c

Browse files
committed
feat: volume copy src dir fix
1 parent 61a6301 commit 910ee3c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pkg/nfs/controllerserver.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ func (cs *ControllerServer) copyFromVolume(ctx context.Context, req *csi.CreateV
320320
if err != nil {
321321
return status.Error(codes.NotFound, err.Error())
322322
}
323-
srcPath := getInternalVolumePath(cs.Driver.workingMountDir, srcVol)
323+
// Note that the source path must include trailing '/.', can't use 'filepath.Join()' as it performs path cleaning
324+
srcPath := fmt.Sprintf("%v/.", getInternalVolumePath(cs.Driver.workingMountDir, srcVol))
324325
dstPath := getInternalVolumePath(cs.Driver.workingMountDir, dstVol)
325326
klog.V(2).Infof("copy volume from volume %v -> %v", srcPath, dstPath)
326327

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

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

0 commit comments

Comments
 (0)