Skip to content

Commit

Permalink
[Darwin] Retrieve data stored into ~/Documents/chip.store (#14233)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple authored and pull[bot] committed Oct 17, 2023
1 parent 33b1619 commit 2353672
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
25 changes: 21 additions & 4 deletions scripts/tests/chiptest/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from datetime import datetime
import typing
import threading
from pathlib import Path
import platform

from enum import Enum, auto
from dataclasses import dataclass
Expand Down Expand Up @@ -99,12 +101,26 @@ def Run(self, runner, paths: ApplicationPaths):
"Unknown test target - don't know which application to run")

tool_cmd = paths.chip_tool
if os.path.exists('/tmp/chip_tool_config.ini'):
os.unlink('/tmp/chip_tool_config.ini')

files_to_unlink = [
'/tmp/chip_tool_config.ini',
'/tmp/chip_tool_config.alpha.ini',
'/tmp/chip_tool_config.beta.ini',
'/tmp/chip_tool_config.gamma.ini',
]

for f in files_to_unlink:
if os.path.exists(f):
os.unlink(f)

# Remove server all_clusters_app or tv_app storage, so it will be commissionable again
if os.path.exists('/tmp/chip_kvs'):
os.unlink('/tmp/chip_kvs')
if platform.system() == 'Linux':
if os.path.exists('/tmp/chip_kvs'):
os.unlink('/tmp/chip_kvs')

if platform.system() == "Darwin":
if os.path.exists(str(Path.home()) + '/Documents/chip.store'):
os.unlink(str(Path.home()) + '/Documents/chip.store')

discriminator = str(randrange(1, 4096))
logging.debug(
Expand Down Expand Up @@ -139,3 +155,4 @@ def Run(self, runner, paths: ApplicationPaths):
finally:
if app_process:
app_process.kill()
app_process.wait(3)
9 changes: 7 additions & 2 deletions src/platform/Darwin/KeyValueStoreManagerImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ - (instancetype)initWithContext:(nonnull NSManagedObjectContext *)context
return model;
}

KeyValueItem * FindItemForKey(NSString * key, NSError ** error)
KeyValueItem * FindItemForKey(NSString * key, NSError ** error, BOOL returnsData)
{
NSFetchRequest * request = [[NSFetchRequest alloc] initWithEntityName:@"KeyValue"];
if (returnsData) {
[request setReturnsObjectsAsFaults:NO];
}
request.predicate = [NSPredicate predicateWithFormat:@"key = %@", key];

NSArray * result = [gContext executeFetchRequest:request error:error];
Expand All @@ -125,6 +128,8 @@ - (instancetype)initWithContext:(nonnull NSManagedObjectContext *)context
return (KeyValueItem *) [result objectAtIndex:0];
}

KeyValueItem * FindItemForKey(NSString * key, NSError ** error) { return FindItemForKey(key, error, false); }

}

KeyValueStoreManagerImpl KeyValueStoreManagerImpl::sInstance;
Expand Down Expand Up @@ -196,7 +201,7 @@ - (instancetype)initWithContext:(nonnull NSManagedObjectContext *)context
ReturnErrorCodeIf(key == nullptr, CHIP_ERROR_INVALID_ARGUMENT);
ReturnErrorCodeIf(offset != 0, CHIP_ERROR_INVALID_ARGUMENT);

KeyValueItem * item = FindItemForKey([[NSString alloc] initWithUTF8String:key], nil);
KeyValueItem * item = FindItemForKey([[NSString alloc] initWithUTF8String:key], nil, true);
if (!item) {
return CHIP_ERROR_KEY_NOT_FOUND;
}
Expand Down

0 comments on commit 2353672

Please sign in to comment.