Skip to content

Commit

Permalink
fix: sef fault on linux due to non existent path (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
kneekey23 authored Oct 25, 2021
1 parent 081b0f9 commit 4e670ac
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Source/AwsCommonRuntimeKit/sdkutils/CRTAWSProfileCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ import AwsCSdkUtils
public class CRTAWSProfileCollection {
var rawValue: OpaquePointer

public init(fromFile path: String,
source: CRTAWSProfileSourceType,
allocator: Allocator = defaultAllocator) {
public init?(fromFile path: String,
source: CRTAWSProfileSourceType,
allocator: Allocator = defaultAllocator) {
var finalizedPath = path
if path.hasPrefix("~"),
let homeDirectory = aws_get_home_directory(allocator.rawValue),
let homeDirectoryString = String(awsString: homeDirectory) {
finalizedPath = homeDirectoryString + path.dropFirst()
}
let awsString = AWSString(finalizedPath, allocator: allocator)
self.rawValue = aws_profile_collection_new_from_file(allocator.rawValue,
awsString.rawValue,
source.rawValue)
guard let profilePointer = aws_profile_collection_new_from_file(allocator.rawValue,
awsString.rawValue,
source.rawValue) else {
return nil
}
self.rawValue = profilePointer
}

public init(fromBuffer buffer: ByteBuffer,
Expand All @@ -28,9 +31,9 @@ public class CRTAWSProfileCollection {
let byteCount = byteArray.count
let byteBuf = byteArray.withUnsafeMutableBufferPointer { pointer -> aws_byte_buf in
let byteBuf = aws_byte_buf(len: byteCount,
buffer: pointer.baseAddress,
capacity: byteCount,
allocator: allocator.rawValue)
buffer: pointer.baseAddress,
capacity: byteCount,
allocator: allocator.rawValue)
return byteBuf
}
let pointer: UnsafePointer<aws_byte_buf> = fromPointer(ptr: byteBuf)
Expand Down

0 comments on commit 4e670ac

Please sign in to comment.