-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create lockfile for improved compatibility with 3rd party updaters
- Loading branch information
1 parent
7233bb9
commit cfd9630
Showing
6 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// SUGlobalUpdateLock.h | ||
// Sparkle | ||
// | ||
// Created by Bibhas Acharya on 7/12/20. | ||
// Copyright © 2020 Sparkle Project. All rights reserved. | ||
// | ||
|
||
#ifndef SUGLOBALUPDATELOCK_H | ||
#define SUGLOBALUPDATELOCK_H | ||
|
||
#if __has_feature(modules) | ||
@import Foundation; | ||
#else | ||
#import <Foundation/Foundation.h> | ||
#endif | ||
|
||
@interface SUGlobalUpdateLock : NSObject | ||
|
||
+ (SUGlobalUpdateLock *)sharedLock; | ||
- (void)lock; | ||
- (void)unlock; | ||
|
||
@end | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// SUGlobalUpdateFileLock.m | ||
// Sparkle | ||
// | ||
// Created by Bibhas Acharya on 7/12/20. | ||
// Copyright © 2020 Sparkle Project. All rights reserved. | ||
// | ||
|
||
#import "SUGlobalUpdateLock.h" | ||
#import "SULog.h" | ||
|
||
|
||
@implementation SUGlobalUpdateLock | ||
|
||
+ (SUGlobalUpdateLock *)sharedLock | ||
{ | ||
static dispatch_once_t once; | ||
static SUGlobalUpdateLock *sharedInstance = nil; | ||
dispatch_once(&once, ^{ | ||
sharedInstance = [self new]; | ||
}); | ||
return sharedInstance; | ||
} | ||
|
||
- (void)lock | ||
{ | ||
NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
NSString *fileLockPath = [self fileLockPath]; | ||
|
||
BOOL success = [fileManager createFileAtPath:fileLockPath contents:nil attributes:nil]; | ||
if (!success) { | ||
SULog(SULogLevelDefault, @"Couldn't create lockfile at: %@", fileLockPath); | ||
} | ||
} | ||
|
||
- (void)unlock | ||
{ | ||
NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
NSString *fileLockPath = [self fileLockPath]; | ||
|
||
if ([fileManager fileExistsAtPath:fileLockPath]) { | ||
NSError *error = nil; | ||
[fileManager removeItemAtPath:fileLockPath error:&error]; | ||
if (error != nil) { | ||
SULog(SULogLevelError, @"Couldn't remove lockfile at: %@ [%@]", fileLockPath, [error localizedDescription]); | ||
} | ||
} | ||
} | ||
|
||
- (NSString *)identifier | ||
{ | ||
NSString *resp = [[NSBundle mainBundle] bundleIdentifier]; | ||
if (resp == nil) { | ||
// If there's no bundle identifier, use the executable path | ||
resp = [[[NSBundle mainBundle] executablePath] stringByReplacingOccurrencesOfString:@"/" withString:@"."]; | ||
} | ||
return resp; | ||
} | ||
|
||
- (NSString *)fileLockPath | ||
{ | ||
return [NSString stringWithFormat:@"/private/var/tmp/%@.Sparkle.pid", [self identifier]]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters