Reject ambiguous library names and empty library-set entries (#33)
* Reject ambiguous library names and empty library-set entries get_library_id() silently picked the first library matching a requested name, so two libraries sharing a name would sync whichever happened to come first in the server's response - not necessarily the one the operator meant. It now raises ConfigError when a name matches more than one library. resolve_libraries() rejects an empty entry produced by an empty LIBRARY_ID, 'a::b', or a leading/trailing ':' the same way, instead of silently logging 'library not found' and moving on. * Clarify get_library_id's ambiguity docstring and error message Copilot review: the input can be a name or an ID, and the error said 'Library name' even for an ID collision; use neutral wording. Also made the docstring's second sentence a complete one. --------- Co-authored-by: Maxim Shulga <maxim.shulga@alludo.com>
This commit is contained in:
1 parent
6f8af2cfa4
commit
ba5ad177b7
4 files changed
+86
-6
No files matched your search
+16
-4
@@ -166,10 +166,22 @@ class SeafileClient:
|
||||
_lg.info("Seafile daemon is stopped")
|
||||
|
||||
def get_library_id(self, library) -> Optional[str]:
|
||||
for lib_id, lib_name in self.remote_libraries.items():
|
||||
if library in (lib_id, lib_name):
|
||||
return lib_id
|
||||
return None
|
||||
"""
|
||||
Resolve a requested name or ID to the one library ID it names.
|
||||
|
||||
Library IDs are unique, but two libraries can share a name. Silently
|
||||
matching more than one and picking the first would sync whichever
|
||||
happened to come first in the server's response, not necessarily the
|
||||
one requested.
|
||||
"""
|
||||
matches = [lib_id for lib_id, lib_name in self.remote_libraries.items()
|
||||
if library in (lib_id, lib_name)]
|
||||
if len(matches) > 1:
|
||||
raise ConfigError(
|
||||
f"{library!r} matches {len(matches)} libraries on the server; "
|
||||
"use the library ID instead"
|
||||
)
|
||||
return matches[0] if matches else None
|
||||
|
||||
def sync_lib(self, lib_id: str, lib_dir: str) -> bool:
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user