File tree Expand file tree Collapse file tree 2 files changed +14
-9
lines changed
Sources/ContainerCommands/Image Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,12 @@ extension Application {
4040 var global : Flags . Global
4141
4242 public func run( ) async throws {
43- let tempFile = FileManager . default. temporaryDirectory. appendingPathComponent ( " temp-file.tar " )
43+ let tempFile = FileManager . default. temporaryDirectory. appendingPathComponent ( " \( UUID ( ) . uuidString) .tar " )
44+ defer {
45+ try ? FileManager . default. removeItem ( at: tempFile)
46+ }
47+
48+ // Read from stdin
4449 if input == nil {
4550 guard FileManager . default. createFile ( atPath: tempFile. path ( ) , contents: nil ) else {
4651 throw ContainerizationError ( . internalError, message: " unable to create temporary file " )
@@ -56,9 +61,7 @@ extension Application {
5661 if chunk. isEmpty { break }
5762 outputHandle. write ( chunk)
5863 }
59- }
60- defer {
61- try ? FileManager . default. removeItem ( at: tempFile)
64+ try outputHandle. close ( )
6265 }
6366
6467 guard FileManager . default. fileExists ( atPath: input ?? tempFile. path ( ) ) else {
Original file line number Diff line number Diff line change @@ -91,17 +91,18 @@ extension Application {
9191
9292 }
9393
94- let tempFile = FileManager . default. temporaryDirectory. appendingPathComponent ( " temp-file.tar " )
95- guard FileManager . default. createFile ( atPath: tempFile. path ( ) , contents: nil ) else {
96- throw ContainerizationError ( . internalError, message: " unable to create temporary file " )
97- }
98-
94+ let tempFile = FileManager . default. temporaryDirectory. appendingPathComponent ( " \( UUID ( ) . uuidString) .tar " )
9995 defer {
10096 try ? FileManager . default. removeItem ( at: tempFile)
10197 }
10298
99+ guard FileManager . default. createFile ( atPath: tempFile. path ( ) , contents: nil ) else {
100+ throw ContainerizationError ( . internalError, message: " unable to create temporary file " )
101+ }
102+
103103 try await ClientImage . save ( references: references, out: output ?? tempFile. path ( ) , platform: p)
104104
105+ // Write to stdout
105106 if output == nil {
106107 guard let outputHandle = try ? FileHandle ( forReadingFrom: tempFile) else {
107108 throw ContainerizationError ( . internalError, message: " unable to open temporary file for reading " )
@@ -113,6 +114,7 @@ extension Application {
113114 if chunk. isEmpty { break }
114115 FileHandle . standardOutput. write ( chunk)
115116 }
117+ try outputHandle. close ( )
116118 }
117119
118120 progress. finish ( )
You can’t perform that action at this time.
0 commit comments