-
Notifications
You must be signed in to change notification settings - Fork 284
Description
This comes from #1317
I'm seriously considering if Updater on its own should not support local target caching at all -- it's not part of the spec, it has these sharp corners WRT urls being used as file paths, and I think it could be handled as well by an external component like a derived class (that we may or may not want to provide).
People, me included, keep getting confused about what targetpaths are: it should be clear that they are just url-fragments that serve two purposes:
- work as identifiers for the target that can also be used to resolve delegations
- form the final download URL for the target
but currently the client implementation uses targetpath also as a local filesystem path. Spec does not demand using the path (it does sort of say files should be saved with the same filename that was used in URL however -- this is likely spec overreach). Separating the caching so that a spec compliant updater can be implemented without all the filesystem path issues would make it clearer what targetpaths are.
Non-caching updater could look like
class Updater:
def __init__(...)
def refresh()
def lookup(name:str ) -> TargetFile
# here caller can use TargetFile.hashes_match(file_obj) if they want to check a local file
def download(target: TargetFile, local_path: str) # write the file to given path
The CachingUpdater would add:
class CacheUpdater(Updater)
def __init__(..., cache_dir:str)
def get_cached(target: TargetFile) -> Optional[str] # returns local path if it was cached
def download(target: TargetFile) -> str # writes the file to cache (if needed), returns local path
# possibly should still offer a way to write to given path like Updater.download() (and still cache?)