-
Notifications
You must be signed in to change notification settings - Fork 311
Description
I'm trying to copy a file over to a Windows container following cp example in the examples folder. The following is my code:
`public static async Task CopyFileToPodAsync2(IKubernetes client, string name, string nsp, string container, string sourceFilePath, string destinationFilePath, CancellationToken cancellationToken = default)
{
ValidatePathParameters(sourceFilePath, destinationFilePath);
var handler = new ExecAsyncCallback(async (stdIn, stdOut, stdError) =>
{
var fileInfo = new FileInfo(destinationFilePath);
try
{
using var memoryStream = new MemoryStream();
using var inputFileStream = File.OpenRead(sourceFilePath);
using var tarOutputStream = new TarOutputStream(memoryStream, Encoding.Default)
{
IsStreamOwner = false
};
var fileSize = inputFileStream.Length;
var entry = TarEntry.CreateTarEntry(fileInfo.Name);
entry.Size = fileSize;
tarOutputStream.PutNextEntry(entry);
await inputFileStream.CopyToAsync(tarOutputStream);
tarOutputStream.CloseEntry();
memoryStream.Position = 0;
await memoryStream.CopyToAsync(stdIn);
await stdIn.FlushAsync();
}
catch (Exception ex)
{
throw new IOException($"Copy command failed: {ex.Message}");
}
using StreamReader streamReader = new StreamReader(stdError);
while (!streamReader.EndOfStream)
{
string error = await streamReader.ReadToEndAsync();
throw new IOException($"Copy command failed: {error}");
}
});
string destinationFolder = GetFolderName(destinationFilePath);
// Use Windows-specific command to extract the tar stream to the destination folder
try
{
var r = await client.NamespacedPodExecAsync(
name,
nsp,
container,
new string[] { "cmd", "/c", $"powershell -Command \"tar -xmf - -C {destinationFolder}\"" },
false,
handler,
cancellationToken).ConfigureAwait(false);
return r;
}
catch (Exception ex)
{
throw new IOException($"Command execution failed: {ex.Message}");
}}`
The destination folder is C:\Test which exists on the machine. Even when I create a new Folder adding mkdir C:\Test2 to the command, I do not get an error but nothing happens.
Could someone point out what I'm doing wrong?