-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from SwiftPackageIndex/issue-3069
Issue 3069
- Loading branch information
Showing
4 changed files
with
47 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+799 KB
Tests/DocUploadBundleTests/Fixtures/prod-apple-swift-metrics-main-e6a00d36.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Foundation | ||
|
||
|
||
enum TempDirError: LocalizedError { | ||
case invalidPath(String) | ||
} | ||
|
||
|
||
class TempDir { | ||
let path: String | ||
|
||
init() throws { | ||
let tempDir = FileManager.default.temporaryDirectory | ||
.appendingPathComponent(UUID().uuidString) | ||
path = tempDir.path | ||
try FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil) | ||
precondition(FileManager.default.fileExists(atPath: path), "failed to create temp dir") | ||
} | ||
|
||
deinit { | ||
do { | ||
try FileManager.default.removeItem(atPath: path) | ||
} catch { | ||
print("⚠️ failed to delete temp directory: \(error.localizedDescription)") | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
func withTempDir<T>(body: (String) async throws -> T) async throws -> T { | ||
let tmp = try TempDir() | ||
return try await body(tmp.path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters