Skip to content

Commit 924b612

Browse files
committed
Revert "Revert "Avoid use of temp_await in PackageRegistryToolTests.swift" (#7169)"
This reverts commit 1eb64ab.
1 parent d457fa4 commit 924b612

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

Sources/Basics/Archiver/Archiver.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public protocol Archiver {
5656
}
5757

5858
extension Archiver {
59+
/// Asynchronously extracts the contents of an archive to a destination folder.
60+
///
61+
/// - Parameters:
62+
/// - archivePath: The `AbsolutePath` to the archive to extract.
63+
/// - destinationPath: The `AbsolutePath` to the directory to extract to.
5964
public func extract(
6065
from archivePath: AbsolutePath,
6166
to destinationPath: AbsolutePath
@@ -80,5 +85,31 @@ extension Archiver {
8085
try await safe_async {
8186
self.validate(path: path, completion: $0)
8287
}
88+
}
89+
90+
/// Asynchronously compresses the contents of a directory to a destination archive.
91+
///
92+
/// - Parameters:
93+
/// - directory: The `AbsolutePath` to the archive to extract.
94+
/// - destinationPath: The `AbsolutePath` to the directory to extract to.
95+
public func compress(
96+
directory: AbsolutePath,
97+
to destinationPath: AbsolutePath
98+
) async throws {
99+
try await withCheckedThrowingContinuation {
100+
self.compress(directory: directory, to: destinationPath, completion: $0.resume(with:))
101+
}
102+
}
103+
104+
/// Asynchronously validates if a file is an archive.
105+
///
106+
/// - Parameters:
107+
/// - path: The `AbsolutePath` to the archive to validate.
108+
public func validate(
109+
path: AbsolutePath
110+
) async throws -> Bool {
111+
try await withCheckedThrowingContinuation {
112+
self.validate(path: path, completion: $0.resume(with:))
113+
}
83114
}
84115
}

Tests/CommandsTests/PackageRegistryToolTests.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ final class PackageRegistryToolTests: CommandsTestCase {
279279

280280
// TODO: Test example with login and password
281281

282-
func testArchiving() throws {
282+
func testArchiving() async throws {
283283
#if os(Linux)
284284
// needed for archiving
285285
guard SPM_posix_spawn_file_actions_addchdir_np_supported() else {
@@ -293,7 +293,7 @@ final class PackageRegistryToolTests: CommandsTestCase {
293293
let metadataFilename = SwiftPackageRegistryTool.Publish.metadataFilename
294294

295295
// git repo
296-
try withTemporaryDirectory { temporaryDirectory in
296+
try await withTemporaryDirectory { temporaryDirectory in
297297
let packageDirectory = temporaryDirectory.appending("MyPackage")
298298
try localFileSystem.createDirectory(packageDirectory)
299299

@@ -320,12 +320,12 @@ final class PackageRegistryToolTests: CommandsTestCase {
320320
observabilityScope: observability.topScope
321321
)
322322

323-
try validatePackageArchive(at: archivePath)
323+
try await validatePackageArchive(at: archivePath)
324324
XCTAssertTrue(archivePath.isDescendant(of: workingDirectory))
325325
}
326326

327327
// not a git repo
328-
try withTemporaryDirectory { temporaryDirectory in
328+
try await withTemporaryDirectory { temporaryDirectory in
329329
let packageDirectory = temporaryDirectory.appending("MyPackage")
330330
try localFileSystem.createDirectory(packageDirectory)
331331

@@ -350,11 +350,11 @@ final class PackageRegistryToolTests: CommandsTestCase {
350350
observabilityScope: observability.topScope
351351
)
352352

353-
try validatePackageArchive(at: archivePath)
353+
try await validatePackageArchive(at: archivePath)
354354
}
355355

356356
// canonical metadata location
357-
try withTemporaryDirectory { temporaryDirectory in
357+
try await withTemporaryDirectory { temporaryDirectory in
358358
let packageDirectory = temporaryDirectory.appending("MyPackage")
359359
try localFileSystem.createDirectory(packageDirectory)
360360

@@ -385,17 +385,17 @@ final class PackageRegistryToolTests: CommandsTestCase {
385385
observabilityScope: observability.topScope
386386
)
387387

388-
let extractedPath = try validatePackageArchive(at: archivePath)
388+
let extractedPath = try await validatePackageArchive(at: archivePath)
389389
XCTAssertFileExists(extractedPath.appending(component: metadataFilename))
390390
}
391391

392392
@discardableResult
393-
func validatePackageArchive(at archivePath: AbsolutePath) throws -> AbsolutePath {
393+
func validatePackageArchive(at archivePath: AbsolutePath) async throws -> AbsolutePath {
394394
XCTAssertFileExists(archivePath)
395395
let archiver = ZipArchiver(fileSystem: localFileSystem)
396396
let extractPath = archivePath.parentDirectory.appending(component: UUID().uuidString)
397397
try localFileSystem.createDirectory(extractPath)
398-
try temp_await { archiver.extract(from: archivePath, to: extractPath, completion: $0) }
398+
try await archiver.extract(from: archivePath, to: extractPath)
399399
try localFileSystem.stripFirstLevel(of: extractPath)
400400
XCTAssertFileExists(extractPath.appending("Package.swift"))
401401
return extractPath
@@ -550,7 +550,7 @@ final class PackageRegistryToolTests: CommandsTestCase {
550550
let archiver = ZipArchiver(fileSystem: localFileSystem)
551551
let extractPath = archivePath.parentDirectory.appending(component: UUID().uuidString)
552552
try localFileSystem.createDirectory(extractPath)
553-
try temp_await { archiver.extract(from: archivePath, to: extractPath, completion: $0) }
553+
try await archiver.extract(from: archivePath, to: extractPath)
554554
try localFileSystem.stripFirstLevel(of: extractPath)
555555

556556
let manifestInArchive = try localFileSystem.readFileContents(extractPath.appending(manifestFile)).contents
@@ -963,7 +963,7 @@ final class PackageRegistryToolTests: CommandsTestCase {
963963
let archiver = ZipArchiver(fileSystem: localFileSystem)
964964
let extractPath = archivePath.parentDirectory.appending(component: UUID().uuidString)
965965
try localFileSystem.createDirectory(extractPath)
966-
try temp_await { archiver.extract(from: archivePath, to: extractPath, completion: $0) }
966+
try await archiver.extract(from: archivePath, to: extractPath)
967967
try localFileSystem.stripFirstLevel(of: extractPath)
968968

969969
let manifestSignature = try ManifestSignatureParser.parse(

0 commit comments

Comments
 (0)