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.
This commit is contained in:
Lukhnos Liu 2020-10-10 07:24:50 -07:00
parent 7d13ea0b41
commit 2f2f18d9e0
1 changed files with 11 additions and 0 deletions

View File

@ -226,6 +226,17 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) {
for (int i = 0; i < entryCount; i++) { for (int i = 0; i < entryCount; i++) {
if (!strcmp(bundleAbsPath, bufs[i].f_mntfromname)) { if (!strcmp(bundleAbsPath, bufs[i].f_mntfromname)) {
free(bufs); 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; return YES;
} }
} }