@@ -56,26 +56,24 @@ final class SMB2FileHandle: @unchecked Sendable {
56
56
createOptions: CreateOptions = [ ] , on client: SMB2Client
57
57
) throws {
58
58
var leaseData = opLock. leaseContext. map { Data ( $0. regions. joined ( ) ) } ?? . init( )
59
-
60
- let ( _, result) = try withExtendedLifetime ( leaseData) {
61
- try path. replacingOccurrences ( of: " / " , with: " \\ " ) . withCString { path in
62
- try client. async_await_pdu ( dataHandler: SMB2FileID . init) {
63
- context, cbPtr -> UnsafeMutablePointer < smb2_pdu > ? in
64
- var req = smb2_create_request ( )
65
- req. requested_oplock_level = opLock. lockLevel
66
- req. impersonation_level = impersonation. rawValue
67
- req. desired_access = desiredAccess. rawValue
68
- req. file_attributes = fileAttributes. rawValue
69
- req. share_access = shareAccess. rawValue
70
- req. create_disposition = createDisposition. rawValue
71
- req. create_options = createOptions. rawValue
72
- req. name = path
73
- leaseData. withUnsafeMutableBytes {
74
- req. create_context = $0. count > 0 ? $0. baseAddress? . assumingMemoryBound ( to: UInt8 . self) : nil
75
- req. create_context_length = UInt32 ( $0. count)
76
- }
77
- return smb2_cmd_create_async ( context, & req, SMB2Client . generic_handler, cbPtr)
59
+ defer { withExtendedLifetime ( leaseData) { } }
60
+ let ( _, result) = try path. replacingOccurrences ( of: " / " , with: " \\ " ) . withCString { path in
61
+ try client. async_await_pdu ( dataHandler: SMB2FileID . init) {
62
+ context, cbPtr -> UnsafeMutablePointer < smb2_pdu > ? in
63
+ var req = smb2_create_request ( )
64
+ req. requested_oplock_level = opLock. lockLevel
65
+ req. impersonation_level = impersonation. rawValue
66
+ req. desired_access = desiredAccess. rawValue
67
+ req. file_attributes = fileAttributes. rawValue
68
+ req. share_access = shareAccess. rawValue
69
+ req. create_disposition = createDisposition. rawValue
70
+ req. create_options = createOptions. rawValue
71
+ req. name = path
72
+ leaseData. withUnsafeMutableBytes {
73
+ req. create_context = $0. count > 0 ? $0. baseAddress? . assumingMemoryBound ( to: UInt8 . self) : nil
74
+ req. create_context_length = UInt32 ( $0. count)
78
75
}
76
+ return smb2_cmd_create_async ( context, & req, SMB2Client . generic_handler, cbPtr)
79
77
}
80
78
}
81
79
try self . init ( fileDescriptor: result. rawValue, on: client)
@@ -335,24 +333,23 @@ final class SMB2FileHandle: @unchecked Sendable {
335
333
func fcntl< DataType: DataProtocol , R: DecodableResponse > (
336
334
command: IOCtl . Command , args: DataType = Data ( )
337
335
) throws -> R {
338
- try withExtendedLifetime ( args) { args in
339
- var inputBuffer = [ UInt8] ( args)
340
- return try inputBuffer. withUnsafeMutableBytes { buf in
341
- var req = smb2_ioctl_request (
342
- ctl_code: command. rawValue,
343
- file_id: fileId. uuid,
344
- input_offset: 0 , input_count: . init( buf. count) ,
345
- max_input_response: 0 ,
346
- output_offset: 0 , output_count: UInt32 ( client. maximumTransactionSize) ,
347
- max_output_response: 65535 ,
348
- flags: . init( SMB2_0_IOCTL_IS_FSCTL) ,
349
- input: buf. baseAddress
350
- )
351
- return try client. async_await_pdu ( dataHandler: R . init) {
352
- context, cbPtr -> UnsafeMutablePointer < smb2_pdu > ? in
353
- smb2_cmd_ioctl_async ( context, & req, SMB2Client . generic_handler, cbPtr)
354
- } . data
355
- }
336
+ defer { withExtendedLifetime ( args) { } }
337
+ var inputBuffer = [ UInt8] ( args)
338
+ return try inputBuffer. withUnsafeMutableBytes { buf in
339
+ var req = smb2_ioctl_request (
340
+ ctl_code: command. rawValue,
341
+ file_id: fileId. uuid,
342
+ input_offset: 0 , input_count: . init( buf. count) ,
343
+ max_input_response: 0 ,
344
+ output_offset: 0 , output_count: UInt32 ( client. maximumTransactionSize) ,
345
+ max_output_response: 65535 ,
346
+ flags: . init( SMB2_0_IOCTL_IS_FSCTL) ,
347
+ input: buf. baseAddress
348
+ )
349
+ return try client. async_await_pdu ( dataHandler: R . init) {
350
+ context, cbPtr -> UnsafeMutablePointer < smb2_pdu > ? in
351
+ smb2_cmd_ioctl_async ( context, & req, SMB2Client . generic_handler, cbPtr)
352
+ } . data
356
353
}
357
354
}
358
355
0 commit comments