11import * as fs from 'fs' ;
22import * as path from 'path' ;
33import { EqualVersionError , ValueError } from './error' ;
4- import { FetcherInterface } from './fetcher' ;
4+ import { BaseFetcher , Fetcher } from './fetcher' ;
55import { Metadata , Targets } from './models' ;
66import { TargetFile } from './models/file' ;
7- import { Fetcher } from './requestsFetcher' ;
8- import { TrustedMetadataSet } from './trusted_metadata_set' ;
7+ import { TrustedMetadataStore } from './store' ;
98import { updaterConfig } from './utils/config' ;
109import { MetadataKind } from './utils/types' ;
1110
@@ -14,7 +13,7 @@ interface UodaterOptions {
1413 metadataBaseUrl : string ;
1514 targetDir ?: string ;
1615 targetBaseUrl ?: string ;
17- fetcher ?: FetcherInterface ;
16+ fetcher ?: BaseFetcher ;
1817}
1918
2019interface Delegation {
@@ -27,9 +26,9 @@ export class Updater {
2726 private metadataBaseUrl : string ;
2827 private targetDir ?: string ;
2928 private targetBaseUrl ?: string ;
30- private trustedSet : TrustedMetadataSet ;
29+ private trustedSet : TrustedMetadataStore ;
3130 private config : typeof updaterConfig ;
32- private fetcher : FetcherInterface ;
31+ private fetcher : BaseFetcher ;
3332
3433 constructor ( options : UodaterOptions ) {
3534 const { metadataDir, metadataBaseUrl, targetDir, targetBaseUrl, fetcher } =
@@ -42,7 +41,7 @@ export class Updater {
4241 this . targetBaseUrl = targetBaseUrl ;
4342
4443 const data = this . loadLocalMetadata ( MetadataKind . Root ) ;
45- this . trustedSet = new TrustedMetadataSet ( data ) ;
44+ this . trustedSet = new TrustedMetadataStore ( data ) ;
4645 this . config = updaterConfig ;
4746
4847 this . fetcher = fetcher || new Fetcher ( this . config . fetchTimeout ) ;
@@ -208,34 +207,12 @@ export class Updater {
208207 return this . trustedSet . getRole ( role ) ;
209208 }
210209
210+ // Returns the TargetFile instance with information for the given target path.
211+ //
212+ // Implicitly calls refresh if it hasn't already been called.
211213 public async getTargetInfo (
212214 targetPath : string
213215 ) : Promise < TargetFile | undefined > {
214- /***
215- * Returns ``TargetFile`` instance with information for ``target_path``.
216-
217- The return value can be used as an argument to
218- ``download_target()`` and ``find_cached_target()``.
219-
220- If ``refresh()`` has not been called before calling
221- ``get_targetinfo()``, the refresh will be done implicitly.
222-
223- As a side-effect this method downloads all the additional (delegated
224- targets) metadata it needs to return the target information.
225-
226- Args:
227- target_path: `path-relative-URL string
228- <https://url.spec.whatwg.org/#path-relative-url-string>`_
229- that uniquely identifies the target within the repository.
230-
231- Raises:
232- OSError: New metadata could not be written to disk
233- RepositoryError: Metadata failed to verify in some way
234- DownloadError: Download of a metadata file failed in some way
235-
236- Returns:
237- ``TargetFile`` instance or ``None``.
238- ***/
239216 if ( ! this . trustedSet . targets ) {
240217 this . refresh ( ) ;
241218 }
0 commit comments