From 2f2f18d9e0d0449c525697eb43b78586db9deafb Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Sat, 10 Oct 2020 07:24:50 -0700 Subject: [PATCH] Check if the translocated app is still mounted This ensures that, after the Installer has killed the current input method process, the Installer can tell if the translocated input method bundle is no longer mounted. It turns out that getfsstat() may return cached results and a call to statfs() is necessary. This fixes the bug that the Installer did not always correctly report that a new version of the input method has been installed over a previous version. The bug only manifests when getfsstat() returns cached results. That seems to be the case on newer versions of macOS. --- Source/Installer/AppDelegate.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/Installer/AppDelegate.m b/Source/Installer/AppDelegate.m index f8e01341..34887222 100644 --- a/Source/Installer/AppDelegate.m +++ b/Source/Installer/AppDelegate.m @@ -226,6 +226,17 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) { for (int i = 0; i < entryCount; i++) { if (!strcmp(bundleAbsPath, bufs[i].f_mntfromname)) { free(bufs); + + // getfsstat() may return us a cached result, and so we need to get the stat of the mounted fs. + // If statfs() returns an error, the mounted fs is already gone. + struct statfs stat; + int checkResult = statfs(bundleAbsPath, &stat); + if (checkResult != 0) { + // Meaning the app's bundle is not mounted, that is it's not translocated. + // It also means that the app is not loaded. + return NO; + } + return YES; } }