Skip to content

Commit

Permalink
[Issue Alamofire#1333] MultipartFormData temp directory is now create…
Browse files Browse the repository at this point in the history
…d serially.
  • Loading branch information
cnoon committed Sep 10, 2016
1 parent 72958d0 commit b73893d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Source/SessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,19 @@ open class SessionManager {
let fileURL = directoryURL.appendingPathComponent(fileName)

do {
try fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: true, attributes: nil)
var directoryError: Error?

// Create directory inside serial queue to ensure two threads don't do this in parallel
self.queue.sync {
do {
try fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: true, attributes: nil)
} catch {
directoryError = error
}
}

if let directoryError = directoryError { throw directoryError }

try formData.writeEncodedData(to: fileURL)

DispatchQueue.main.async {
Expand Down

0 comments on commit b73893d

Please sign in to comment.