@@ -49,7 +49,7 @@ class RealtimeSuggestionControllerBenchmarkManager: BenchmarkManager {
4949 for (index, taskPath) in taskPaths. prefix ( 1 ) . enumerated ( ) {
5050 if let suggestion = await getCodeSuggestionFromService ( at: taskPath, from: benchmarkDirectory. url) {
5151 await applyCodeSuggestion ( suggestion: suggestion. suggestion, at: suggestion. fileURL)
52- await storeContentInOutputDirectory ( suggestion, for: index+ 1 )
52+ await storeContentInOutputDirectory ( suggestion, for: index+ 1 , in : benchmarkDirectory )
5353 }
5454
5555 }
@@ -139,7 +139,11 @@ class RealtimeSuggestionControllerBenchmarkManager: BenchmarkManager {
139139 }
140140 }
141141
142- func storeContentInOutputDirectory( _ suggestion: SuggestionResponse , for taskNumber: Int ) async {
142+ func storeContentInOutputDirectory(
143+ _ suggestion: SuggestionResponse ,
144+ for taskNumber: Int ,
145+ in benchmarkDirectory: BenchmarkDirectory
146+ ) async {
143147 guard let outputDirPath = await benchmarkSettingsRepository. outputDirectory. firstValue ( ) else {
144148 print ( " Could not retrieve output directory. " )
145149 return
@@ -159,9 +163,20 @@ class RealtimeSuggestionControllerBenchmarkManager: BenchmarkManager {
159163 }
160164 }
161165
166+ var isBenchmarkDirADirectory : ObjCBool = false
167+ let outputBenchmarkDir = outputDir. appendingPathComponent ( benchmarkDirectory. name, isDirectory: true )
168+ if !fileManager. fileExists ( atPath: outputBenchmarkDir. path, isDirectory: & isBenchmarkDirADirectory) || !isBenchmarkDirADirectory. boolValue {
169+ do {
170+ try fileManager. createDirectory ( at: outputBenchmarkDir, withIntermediateDirectories: true , attributes: nil )
171+ } catch {
172+ print ( " Failed to create output directory: " , error)
173+ return
174+ }
175+ }
176+
162177 let timestamp = ISO8601DateFormatter ( ) . string ( from: Date ( ) )
163178 let reformattedTimestamp = timestamp. replacingOccurrences ( of: " : " , with: " - " )
164- let outputFileURL = outputDir . appendingPathComponent ( " Task- \( taskNumber) - \( reformattedTimestamp) .json " )
179+ let outputFileURL = outputBenchmarkDir . appendingPathComponent ( " Task- \( taskNumber) - \( reformattedTimestamp) .json " )
165180
166181 do {
167182 let dto = suggestion. toStoredDTO ( timestamp: timestamp)
0 commit comments