Move library check to separate file in mac crafter
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 20 Jun 2024 06:40:34 +0000 (14:40 +0800)
committerClaudio Cambra <developer@claudiocambra.com>
Mon, 8 Jul 2024 07:41:45 +0000 (15:41 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
admin/osx/mac-crafter/Sources/Utils/Library.swift [new file with mode: 0644]
admin/osx/mac-crafter/Sources/main.swift

diff --git a/admin/osx/mac-crafter/Sources/Utils/Library.swift b/admin/osx/mac-crafter/Sources/Utils/Library.swift
new file mode 100644 (file)
index 0000000..1304f03
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2024 by Claudio Cambra <claudio.cambra@nextcloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+import Foundation
+
+func isLibrary(_ path: String) -> Bool {
+    path.hasSuffix(".dylib") || path.hasSuffix(".framework")
+}
index aed68631f59ff53c44616ebf71823480599fbde2..a1eb85165a4d70c541f43a77dcc2d404d15cadb1 100644 (file)
@@ -73,9 +73,8 @@ struct MacCrafter: ParsableCommand {
         let craftLibDir = "\(currentDir)/\(craftTarget)/lib"
         let craftLibs = try fm.contentsOfDirectory(atPath: craftLibDir)
         for lib in craftLibs {
-            let libPath = "\(craftLibDir)/\(lib)"
-            guard lib.hasSuffix(".dylib") || lib.hasSuffix(".framework") else { continue }
-            try codesign(identity: codeSignIdentity, path: libPath)
+            guard isLibrary(lib) else { continue }
+            try codesign(identity: codeSignIdentity, path: "\(craftLibDir)/\(lib)")
         }
 
         let craftPluginsDir = "\(currentDir)/\(craftTarget)/plugins"
@@ -84,9 +83,8 @@ struct MacCrafter: ParsableCommand {
         }
 
         for case let plugin as String in craftPluginsEnumerator {
-            let pluginPath = "\(craftPluginsDir)/\(plugin)"
-            guard plugin.hasSuffix(".dylib") || plugin.hasSuffix(".framework") else { continue }
-            try codesign(identity: codeSignIdentity, path: pluginPath)
+            guard isLibrary(plugin) else { continue }
+            try codesign(identity: codeSignIdentity, path: "\(craftPluginsDir)/\(plugin)")
         }
 
         print("Crafting Nextcloud Desktop Client...")