From 64ba7f827d14fa2ced520c450eb602c34c49ef78 Mon Sep 17 00:00:00 2001 From: osy <50960678+osy@users.noreply.github.com> Date: Sat, 10 Sep 2022 19:17:13 +0300 Subject: [PATCH] vm: allow creation with illegal path characters in name Fixes #4385 --- Managers/UTMVirtualMachine.m | 2 ++ Managers/UTMVirtualMachine.swift | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Managers/UTMVirtualMachine.m b/Managers/UTMVirtualMachine.m index b81352139..b5cd96605 100644 --- a/Managers/UTMVirtualMachine.m +++ b/Managers/UTMVirtualMachine.m @@ -133,6 +133,8 @@ + (NSString *)virtualMachineName:(NSURL *)url { } + (NSURL *)virtualMachinePath:(NSString *)name inParentURL:(NSURL *)parent { + NSCharacterSet *illegalFileNameCharacters = [NSCharacterSet characterSetWithCharactersInString:@"/:\\?%*|\"<>"]; + name = [[name componentsSeparatedByCharactersInSet:illegalFileNameCharacters] componentsJoinedByString:@"-"]; return [[parent URLByAppendingPathComponent:name] URLByAppendingPathExtension:kUTMBundleExtension]; } diff --git a/Managers/UTMVirtualMachine.swift b/Managers/UTMVirtualMachine.swift index 12291707c..02927944f 100644 --- a/Managers/UTMVirtualMachine.swift +++ b/Managers/UTMVirtualMachine.swift @@ -73,7 +73,7 @@ extension UTMVirtualMachine: ObservableObject { func saveUTM() async throws { let fileManager = FileManager.default let existingPath = path - let newPath = existingPath.deletingLastPathComponent().appendingPathComponent(config.name).appendingPathExtension("utm") + let newPath = UTMVirtualMachine.virtualMachinePath(config.name, inParentURL: existingPath.deletingLastPathComponent()) do { try await config.save(to: existingPath) try await updateRegistryFromConfig()