Skip to content

Commit

Permalink
Merge pull request #1960 from DataDog/ganeshnj/chore/improve-tel
Browse files Browse the repository at this point in the history
RUM-1000 chore: use throwing API to create the file
  • Loading branch information
ganeshnj authored Jul 18, 2024
2 parents d80d1cf + 791fde9 commit 360e232
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions DatadogCore/Sources/Core/Storage/Files/Directory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import Foundation
import DatadogInternal

extension Data {
static let empty = Data()
}

/// Provides interfaces for accessing common properties and operations for a directory.
internal protocol DirectoryProtocol: FileProtocol {
/// Returns list of subdirectories in the directory.
Expand Down Expand Up @@ -106,9 +110,7 @@ internal struct Directory: DirectoryProtocol {
/// Creates file with given name.
func createFile(named fileName: String) throws -> File {
let fileURL = url.appendingPathComponent(fileName, isDirectory: false)
guard FileManager.default.createFile(atPath: fileURL.path, contents: nil, attributes: nil) == true else {
throw InternalError(description: "Cannot create file at path: \(fileURL.path)")
}
try Data.empty.write(to: fileURL, options: .atomic)
return File(url: fileURL)
}

Expand Down

0 comments on commit 360e232

Please sign in to comment.