Skip to content

Commit

Permalink
chore: Remove obsolete member CopyFileAsync (#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Jun 28, 2023
1 parent bfe64e5 commit d3f09da
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 82 deletions.
13 changes: 0 additions & 13 deletions src/Testcontainers/Clients/ITestcontainersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,6 @@ internal interface ITestcontainersClient
/// <returns>A task that completes when the file has been copied.</returns>
Task CopyAsync(string id, FileInfo source, string target, UnixFileModes fileMode, CancellationToken ct = default);

/// <summary>
/// Copies a file to the container.
/// </summary>
/// <param name="id">The container id.</param>
/// <param name="filePath">The path to the file in the container.</param>
/// <param name="fileContent">The content of the file as bytes.</param>
/// <param name="accessMode">The access mode for the file.</param>
/// <param name="userId">The owner of the file.</param>
/// <param name="groupId">The group of the file.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>Task that completes when the file has been copied.</returns>
Task CopyFileAsync(string id, string filePath, byte[] fileContent, int accessMode, int userId, int groupId, CancellationToken ct = default);

/// <summary>
/// Reads a file from the container.
/// </summary>
Expand Down
42 changes: 0 additions & 42 deletions src/Testcontainers/Clients/TestcontainersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,48 +226,6 @@ await Container.ExtractArchiveToContainerAsync(id, "/", tarOutputMemStream, ct)
}
}

/// <inheritdoc />
public async Task CopyFileAsync(string id, string filePath, byte[] fileContent, int accessMode, int userId, int groupId, CancellationToken ct = default)
{
var containerPath = Unix.Instance.NormalizePath(filePath);

using (var tarOutputMemStream = new MemoryStream())
{
using (var tarOutputStream = new TarOutputStream(tarOutputMemStream, Encoding.Default))
{
tarOutputStream.IsStreamOwner = false;

var header = new TarHeader();
header.Name = containerPath;
header.UserId = userId;
header.GroupId = groupId;
header.Mode = accessMode;
header.Size = fileContent.Length;

var entry = new TarEntry(header);

await tarOutputStream.PutNextEntryAsync(entry, ct)
.ConfigureAwait(false);

#if NETSTANDARD2_1_OR_GREATER
await tarOutputStream.WriteAsync(fileContent, ct)
.ConfigureAwait(false);
#else
await tarOutputStream.WriteAsync(fileContent, 0, fileContent.Length, ct)
.ConfigureAwait(false);
#endif

await tarOutputStream.CloseEntryAsync(ct)
.ConfigureAwait(false);
}

tarOutputMemStream.Seek(0, SeekOrigin.Begin);

await Container.ExtractArchiveToContainerAsync(id, "/", tarOutputMemStream, ct)
.ConfigureAwait(false);
}
}

/// <inheritdoc />
public async Task<byte[]> ReadFileAsync(string id, string filePath, CancellationToken ct = default)
{
Expand Down
6 changes: 0 additions & 6 deletions src/Testcontainers/Containers/DockerContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,6 @@ public Task CopyAsync(DirectoryInfo source, string target, UnixFileModes fileMod
return _client.CopyAsync(Id, source, target, fileMode, ct);
}

/// <inheritdoc />
public Task CopyFileAsync(string filePath, byte[] fileContent, int accessMode = 384, int userId = 0, int groupId = 0, CancellationToken ct = default)
{
return _client.CopyFileAsync(Id, filePath, fileContent, accessMode, userId, groupId, ct);
}

/// <inheritdoc />
public Task<byte[]> ReadFileAsync(string filePath, CancellationToken ct = default)
{
Expand Down
21 changes: 0 additions & 21 deletions src/Testcontainers/Containers/IContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,27 +206,6 @@ public interface IContainer : IAsyncDisposable
/// <returns>A task that completes when the file has been copied.</returns>
Task CopyAsync(FileInfo source, string target, UnixFileModes fileMode = Unix.FileMode644, CancellationToken ct = default);

/// <summary>
/// Copies a file to the container.
/// </summary>
/// <param name="filePath">An absolute path as destination in the container.</param>
/// <param name="fileContent">The byte array content of the file.</param>
/// <param name="accessMode">The access mode for the file (default: 0600).</param>
/// <param name="userId">The owner of the file.</param>
/// <param name="groupId">The group of the file.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>Task that completes when the file has been copied.</returns>
/// <remarks>
/// <paramref name="accessMode" /> is a decimal value. Covert chmod (octal) to decimal.
/// <ul>
/// <li>777 octal 🠒 111_111_111 binary 🠒 511 decimal</li>
/// <li>755 octal 🠒 111_101_101 binary 🠒 493 decimal</li>
/// <li>644 octal 🠒 110_100_100 binary 🠒 420 decimal</li>
/// </ul>
/// </remarks>
[Obsolete("Use CopyAsync(byte[], string, UnixFileMode, CancellationToken) or one of its overloads.")]
Task CopyFileAsync(string filePath, byte[] fileContent, int accessMode = 384, int userId = 0, int groupId = 0, CancellationToken ct = default);

/// <summary>
/// Reads a file from the container.
/// </summary>
Expand Down

0 comments on commit d3f09da

Please sign in to comment.