| 28 | namespace mmkv { |
| 29 | |
| 30 | void tryResetFileProtection(const string &path) { |
| 31 | @autoreleasepool { |
| 32 | NSString *nsPath = [NSString stringWithUTF8String:path.c_str()]; |
| 33 | NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:nsPath error:nullptr]; |
| 34 | NSString *protection = [attr valueForKey:NSFileProtectionKey]; |
| 35 | MMKVInfo("protection on [%@] is %@", nsPath, protection); |
| 36 | if ([protection isEqualToString:NSFileProtectionCompleteUntilFirstUserAuthentication] == NO) { |
| 37 | NSMutableDictionary *newAttr = [NSMutableDictionary dictionaryWithDictionary:attr]; |
| 38 | [newAttr setObject:NSFileProtectionCompleteUntilFirstUserAuthentication forKey:NSFileProtectionKey]; |
| 39 | NSError *err = nil; |
| 40 | [[NSFileManager defaultManager] setAttributes:newAttr ofItemAtPath:nsPath error:&err]; |
| 41 | if (err != nil) { |
| 42 | MMKVError("fail to set attribute %@ on [%@]: %@", NSFileProtectionCompleteUntilFirstUserAuthentication, |
| 43 | nsPath, err); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | } // namespace mmkv |