@@ -452,7 +452,7 @@ struct AlertMessage: Identifiable {
452
452
let newName : String = newDefaultVMName ( base: vm. detailsTitleLabel)
453
453
let newPath = UTMQemuVirtualMachine . virtualMachinePath ( for: newName, in: documentsURL)
454
454
455
- try copyItemWithCopyfile ( at: vm. pathUrl, to: newPath)
455
+ try await copyItemWithCopyfile ( at: vm. pathUrl, to: newPath)
456
456
guard let newVM = try ? VMData ( url: newPath) else {
457
457
throw UTMDataError . cloneFailed
458
458
}
@@ -471,20 +471,20 @@ struct AlertMessage: Identifiable {
471
471
/// - Parameters:
472
472
/// - vm: VM to copy
473
473
/// - url: Location to copy to (must be writable)
474
- func export( vm: VMData , to url: URL ) throws {
474
+ func export( vm: VMData , to url: URL ) async throws {
475
475
let sourceUrl = vm. pathUrl
476
476
if fileManager. fileExists ( atPath: url. path) {
477
477
try fileManager. removeItem ( at: url)
478
478
}
479
- try copyItemWithCopyfile ( at: sourceUrl, to: url)
479
+ try await copyItemWithCopyfile ( at: sourceUrl, to: url)
480
480
}
481
481
482
482
/// Save a copy of the VM and all data to arbitary location and delete the original data
483
483
/// - Parameters:
484
484
/// - vm: VM to move
485
485
/// - url: Location to move to (must be writable)
486
486
func move( vm: VMData , to url: URL ) async throws {
487
- try export ( vm: vm, to: url)
487
+ try await export ( vm: vm, to: url)
488
488
guard let newVM = try ? VMData ( url: url) else {
489
489
throw UTMDataError . shortcutCreationFailed
490
490
}
@@ -616,13 +616,13 @@ struct AlertMessage: Identifiable {
616
616
listSelect ( vm: vm)
617
617
}
618
618
619
- func copyItemWithCopyfile( at srcURL: URL , to dstURL: URL ) throws {
620
- // let state = copyfile_state_alloc()
621
- let status = copyfile ( srcURL. path, dstURL. path, nil , copyfile_flags_t ( COPYFILE_ALL | COPYFILE_RECURSIVE | COPYFILE_CLONE | COPYFILE_DATA_SPARSE) )
622
- // copyfile_state_free(state)
623
- if status < 0 {
624
- throw NSError ( domain : NSPOSIXErrorDomain , code : Int ( errno ) )
625
- }
619
+ func copyItemWithCopyfile( at srcURL: URL , to dstURL: URL ) async throws {
620
+ try await Task . detached ( priority : . userInitiated ) {
621
+ let status = copyfile ( srcURL. path, dstURL. path, nil , copyfile_flags_t ( COPYFILE_ALL | COPYFILE_RECURSIVE | COPYFILE_CLONE | COPYFILE_DATA_SPARSE) )
622
+ if status < 0 {
623
+ throw NSError ( domain : NSPOSIXErrorDomain , code : Int ( errno ) )
624
+ }
625
+ } . value
626
626
}
627
627
628
628
// MARK: - Downloading VMs
0 commit comments