mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Protect lock check section
This commit is contained in:
parent
83e76f5c41
commit
a72afc0de6
@ -8,6 +8,7 @@ Change Log
|
||||
### Fixes
|
||||
|
||||
- Fix an issue where octal file permisson in the document inspector was wrong.
|
||||
- Improve general stability.
|
||||
|
||||
|
||||
|
||||
|
@ -1484,25 +1484,40 @@ NSString *const CEIncompatibleConvertedCharKey = @"convertedChar";
|
||||
- (BOOL)canUnlockFileAtURL:(NSURL *)url isLocked:(BOOL *)isLocked lockAgain:(BOOL)lockAgain
|
||||
// ------------------------------------------------------
|
||||
{
|
||||
__block BOOL isFinderLocked = NO;
|
||||
BOOL success = NO;
|
||||
NSError *error = nil;
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
BOOL isFinderLocked = [[fileManager attributesOfItemAtPath:[url path] error:nil] fileIsImmutable];
|
||||
|
||||
if (isFinderLocked) {
|
||||
// Finder Lock がかかっていれば、解除
|
||||
BOOL success = [fileManager setAttributes:@{NSFileImmutable:@NO} ofItemAtPath:[url path] error:nil];
|
||||
if (success) {
|
||||
if (lockAgain) {
|
||||
// フラグが立っていたなら、再びかける
|
||||
[fileManager setAttributes:@{NSFileImmutable:@YES} ofItemAtPath:[url path] error:nil];
|
||||
@synchronized(self) {
|
||||
NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:self];
|
||||
[coordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingWithoutChanges
|
||||
error:&error
|
||||
byAccessor:^(NSURL *newURL)
|
||||
{
|
||||
isFinderLocked = [[fileManager attributesOfItemAtPath:[newURL path] error:nil] fileIsImmutable];
|
||||
}];
|
||||
|
||||
if (isFinderLocked) {
|
||||
// unlock file once
|
||||
success = [fileManager setAttributes:@{NSFileImmutable:@NO} ofItemAtPath:[url path] error:nil];
|
||||
if (success) {
|
||||
// lock file again if needed
|
||||
if (lockAgain) {
|
||||
[fileManager setAttributes:@{NSFileImmutable:@YES} ofItemAtPath:[url path] error:nil];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NO;
|
||||
// no-lock file is always treated as success
|
||||
success = YES;
|
||||
}
|
||||
}
|
||||
|
||||
if (isLocked) {
|
||||
*isLocked = isFinderLocked;
|
||||
}
|
||||
return YES;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user