 final class Files {
     
     let storageDirectory: URL
+    
+    private let queue = DispatchQueue(label: "com.tuskit.files")
     
     /// Pass a directory to store the local cache in.
     /// - Parameter storageDirectory: Leave nil for the documents dir. Pass a relative path for a dir inside the documents dir. Pass an absolute path for storing files there.

    /// - Returns: The URL of the stored file
    @discardableResult
    func store(data: Data, id: UUID) throws -> URL {
        guard !data.isEmpty else { throw FilesError.dataIsEmpty }
        try makeDirectoryIfNeeded()
        let fileName = id.uuidString
        
        let targetLocation = storageDirectory.appendingPathComponent(fileName)
        try data.write(to: targetLocation)
        return targetLocation
    }
    
    /// Removes metadata and its related file from disk

    /// - Returns: The URL of the location where the metadata is stored.
    @discardableResult
    func encodeAndStore(metaData: UploadMetadata) throws -> URL {
        try queue.sync {
            guard FileManager.default.fileExists(atPath: metaData.filePath.path) else {
                // Could not find the file that's related to this metadata.
                throw FilesError.relatedFileNotFound
            }
            
            let targetLocation = metaData.filePath.appendingPathExtension("plist")
            try self.makeDirectoryIfNeeded()
            
            let encoder = PropertyListEncoder()
            let encodedData = try encoder.encode(metaData)
            try encodedData.write(to: targetLocation, options: .atomic)
            return targetLocation
        }
    }
    
    /// Load metadata from store and find matching one by id
