Skip to content

Commit

Permalink
Pass metadata DB path when subsetting, too.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas FitzRoy-Dale committed Jan 2, 2024
1 parent 242d0a6 commit bef3c22
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions rime/filesystem/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def is_device_filesystem(cls, path):
return os.path.exists(os.path.join(path, 'data', 'data', 'android'))

@classmethod
def create(cls, id_: str, root: str, template: Optional[DeviceFilesystem] = None) -> DeviceFilesystem:
def create(cls, id_: str, root: str, metadata_db_path: str, template: Optional[DeviceFilesystem] = None) -> DeviceFilesystem:
if os.path.exists(root):
raise FileExistsError(root)

os.makedirs(root)
os.makedirs(os.path.join(root, 'data', 'data', 'android'))

obj = cls(id_, root)
obj = cls(id_, root, metadata_db_path)
obj._settings.set_subset_fs(True)
return obj

Expand Down Expand Up @@ -128,8 +128,8 @@ def is_device_filesystem(cls, path):
return zipfile.Path(zp, os.path.join(main_dir.name, 'data', 'data', 'android/')).exists()

@classmethod
def create(cls, id_: str, root: str, template: Optional['DeviceFilesystem'] = None) -> 'DeviceFilesystem':
return AndroidDeviceFilesystem.create(id_, root)
def create(cls, id_: str, root: str, metadata_db_path: str, template: Optional['DeviceFilesystem'] = None) -> 'DeviceFilesystem':
return AndroidDeviceFilesystem.create(id_, root, metadata_db_path)

def is_subset_filesystem(self) -> bool:
return self._settings.is_subset_fs()
Expand Down
16 changes: 8 additions & 8 deletions rime/filesystem/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def is_device_filesystem(cls, path):
)

@classmethod
def create(cls, id_: str, root: str, template: Optional['DeviceFilesystem'] = None) -> 'DeviceFilesystem':
def create(cls, id_: str, root: str, metadata_db_path: str, template: Optional['DeviceFilesystem'] = None) -> 'DeviceFilesystem':
if os.path.exists(root):
raise FileExistsError(root)

Expand Down Expand Up @@ -228,7 +228,7 @@ def create(cls, id_: str, root: str, template: Optional['DeviceFilesystem'] = No
with open(os.path.join(root, 'Info.plist'), 'wb') as dst:
shutil.copyfileobj(src, dst)

obj = cls(id_, root, writeable_manifest=True)
obj = cls(id_, root, metadata_db_path, writeable_manifest=True)
obj._settings.set_subset_fs(True)
return obj

Expand Down Expand Up @@ -366,13 +366,13 @@ def is_device_filesystem(cls, path) -> bool:
)

@classmethod
def create(cls, id_: str, root: str, template: Optional['DeviceFilesystem'] = None) -> 'DeviceFilesystem':
return IosDeviceFilesystem.create(id_, root, template=template)
def create(cls, id_: str, root: str, metadata_db_path, template: Optional['DeviceFilesystem'] = None) -> 'DeviceFilesystem':
return IosDeviceFilesystem.create(id_, root, metadata_db_path, template=template)

def is_subset_filesystem(self) -> bool:
return self._settings.is_subset_fs()

def scandir(self, path) -> list[str]:
def scandir(self, path) -> list[DirEntry]:
return self._converter.scandir(path)

def exists(self, path) -> bool:
Expand All @@ -390,7 +390,7 @@ def getsize(self, path) -> int:
with zipfile.ZipFile(self.root) as zp:
# get the main directory contained in the .zip container file
main_dir = self.get_main_dir(zp)
return zp.getinfo(os.path.join(main_dir, self._converter.get_hashed_pathname(path))).file_size
return zp.getinfo(os.path.join(str(main_dir), self._converter.get_hashed_pathname(path))).file_size

def ios_open_raw(self, path, mode):
# TODO: mode
Expand Down Expand Up @@ -431,7 +431,7 @@ def lock(self, locked: bool):
with zipfile.ZipFile(self.root, 'w') as zp:
# get the main directory contained in the .zip container file
main_dir = self.get_main_dir(zp)
with zp.open(os.path.join(main_dir, '_rime_settings.db'), 'w') as zf:
with zp.open(os.path.join(str(main_dir), '_rime_settings.db'), 'w') as zf:
zf.write(self.temp_settings.read())

def is_locked(self) -> bool:
Expand Down Expand Up @@ -596,7 +596,7 @@ def decrypt_file(self, path, decrypted_hashed_pathname):

_, relative_path = path.split('/', 1)

self._backup.extract_file(
self._backup.extract_file( # type: ignore[union-attr]
relative_path=relative_path,
output_filename=os.path.join(self.root, decrypted_hashed_pathname)
)
Expand Down
3 changes: 2 additions & 1 deletion rime/filesystem/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def create_empty_subset_of(self, fs: DeviceFilesystem, key: str, locked: bool =
if not self.is_valid_device_id(key):
raise ValueError(f"Invalid device ID: {key}")

self.filesystems[key] = fs.__class__.create(key, path, template=fs)
metadata_db_path = os.path.join(self.metadata_path, key + '.sqlite3')
self.filesystems[key] = fs.__class__.create(key, path, metadata_db_path, template=fs)
self.filesystems[key].lock(locked)

return self[key]
Expand Down

0 comments on commit bef3c22

Please sign in to comment.