From c1d9c6eb2cf44ad813043c581f5fa93c1c1a3edb Mon Sep 17 00:00:00 2001 From: gnattu Date: Mon, 13 May 2024 00:35:03 +0800 Subject: [PATCH 1/3] Fix migration logic This is really badly written two years ago and never got a chance to test it. It is wrong in two ways: - The new folder creation needs to be performed before the item moving - The item moving only need to be performed when the new folder has to be crreated --- Jellyfin Server/AppDelegate.swift | 37 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/Jellyfin Server/AppDelegate.swift b/Jellyfin Server/AppDelegate.swift index e6d544f..5a945f1 100755 --- a/Jellyfin Server/AppDelegate.swift +++ b/Jellyfin Server/AppDelegate.swift @@ -29,25 +29,6 @@ class AppDelegate: NSObject, NSApplicationDelegate { } private func createAppFolder() { - // Old contents were stored in ~/.local/share - // Move to ~/Library/Application Support/Jellyfin - if directoryExists(path: localShareJellyfinFolder.path) { - do { - let contents = try FileManager.default.contentsOfDirectory(atPath: localShareJellyfinFolder.path) - - for contentName in contents { - let oldPath = localShareJellyfinFolder.appendingPathComponent(contentName) - let newPath = applicationSupportJellyfinFolder.appendingPathComponent(contentName) - try FileManager.default.moveItem(atPath: oldPath.path, - toPath: newPath.path) - } - - try FileManager.default.removeItem(atPath: localShareJellyfinFolder.path) - } catch { - present(alert: "Jellyfin Server was unable to properly migrate old directories.") - } - } - if !directoryExists(path: applicationSupportJellyfinFolder.path) { do { try FileManager.default.createDirectory(atPath: applicationSupportJellyfinFolder.path, @@ -55,6 +36,24 @@ class AppDelegate: NSObject, NSApplicationDelegate { } catch { present(alert: "Jellyfin Server was unable to properly create necessary directories.") } + // Old contents were stored in ~/.local/share + // Move to ~/Library/Application Support/Jellyfin + if directoryExists(path: localShareJellyfinFolder.path) { + do { + let contents = try FileManager.default.contentsOfDirectory(atPath: localShareJellyfinFolder.path) + + for contentName in contents { + let oldPath = localShareJellyfinFolder.appendingPathComponent(contentName) + let newPath = applicationSupportJellyfinFolder.appendingPathComponent(contentName) + try FileManager.default.moveItem(atPath: oldPath.path, + toPath: newPath.path) + } + + try FileManager.default.removeItem(atPath: localShareJellyfinFolder.path) + } catch { + present(alert: "Jellyfin Server was unable to properly migrate old directories.") + } + } } } From 3e6593123eb63ebd37303b7ed49dfbe26bb084db Mon Sep 17 00:00:00 2001 From: gnattu Date: Mon, 13 May 2024 01:23:37 +0800 Subject: [PATCH 2/3] Use old path instead of doing a migration --- Jellyfin Server/AppDelegate.swift | 38 ++++++------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/Jellyfin Server/AppDelegate.swift b/Jellyfin Server/AppDelegate.swift index 5a945f1..6439296 100755 --- a/Jellyfin Server/AppDelegate.swift +++ b/Jellyfin Server/AppDelegate.swift @@ -18,7 +18,6 @@ class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_: Notification) { statusItem.button?.image = NSImage(named: "StatusBarButtonImage") - createAppFolder() startJellyfinTask() createStatusBarMenu() } @@ -28,35 +27,6 @@ class AppDelegate: NSObject, NSApplicationDelegate { jellyfinProcess.waitUntilExit() } - private func createAppFolder() { - if !directoryExists(path: applicationSupportJellyfinFolder.path) { - do { - try FileManager.default.createDirectory(atPath: applicationSupportJellyfinFolder.path, - withIntermediateDirectories: true) - } catch { - present(alert: "Jellyfin Server was unable to properly create necessary directories.") - } - // Old contents were stored in ~/.local/share - // Move to ~/Library/Application Support/Jellyfin - if directoryExists(path: localShareJellyfinFolder.path) { - do { - let contents = try FileManager.default.contentsOfDirectory(atPath: localShareJellyfinFolder.path) - - for contentName in contents { - let oldPath = localShareJellyfinFolder.appendingPathComponent(contentName) - let newPath = applicationSupportJellyfinFolder.appendingPathComponent(contentName) - try FileManager.default.moveItem(atPath: oldPath.path, - toPath: newPath.path) - } - - try FileManager.default.removeItem(atPath: localShareJellyfinFolder.path) - } catch { - present(alert: "Jellyfin Server was unable to properly migrate old directories.") - } - } - } - } - private func startJellyfinTask() { let jellyfinPath = Bundle.main.path(forAuxiliaryExecutable: "jellyfin") let ffmpegPath = Bundle.main.path(forAuxiliaryExecutable: "ffmpeg") @@ -73,7 +43,13 @@ class AppDelegate: NSObject, NSApplicationDelegate { } jellyfinProcess.launchPath = jellyfinPath - jellyfinProcess.arguments = ["--webdir", webUIPath, "--ffmpeg", ffmpegPath, "--datadir", applicationSupportJellyfinFolder.path] + jellyfinProcess.arguments = ["--webdir", webUIPath, "--ffmpeg", ffmpegPath, "--datadir"] + + if directoryExists(path: localShareJellyfinFolder.path) { + jellyfinProcess.arguments?.append(localShareJellyfinFolder.path) + } else { + jellyfinProcess.arguments?.append(applicationSupportJellyfinFolder.path) + } do { try jellyfinProcess.run() From 87fb95b38647d0fdeead5b4aa0b47fe120ac622b Mon Sep 17 00:00:00 2001 From: gnattu Date: Mon, 13 May 2024 09:02:23 +0800 Subject: [PATCH 3/3] Fix log path Also check for old path in this case --- Jellyfin Server/ActionManager.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jellyfin Server/ActionManager.swift b/Jellyfin Server/ActionManager.swift index 28a375d..cbf40c5 100644 --- a/Jellyfin Server/ActionManager.swift +++ b/Jellyfin Server/ActionManager.swift @@ -15,7 +15,7 @@ enum ActionManager { } static func showLogs() { - let logFolder = applicationSupportJellyfinFolder.appendingPathComponent("/log") + let logFolder = directoryExists(path: localShareJellyfinFolder.path) ? localShareJellyfinFolder.appendingPathComponent("/log") : applicationSupportJellyfinFolder.appendingPathComponent("/log") NSWorkspace.shared.selectFile(nil, inFileViewerRootedAtPath: logFolder.path) }