@@ -23,44 +23,44 @@ export enum REPO_TYPE_T {
2323}
2424
2525export interface CachedFileInfo {
26- file_name : string ;
27- file_path : string ;
28- blob_path : string ;
29- size_on_disk : number ;
26+ filename : string ;
27+ filePath : string ;
28+ blobPath : string ;
29+ sizeOnDisk : number ;
3030
31- blob_last_accessed : number ;
32- blob_last_modified : number ;
31+ blobLastAccessed : number ;
32+ blobLastModified : number ;
3333}
3434
3535export interface CachedRevisionInfo {
36- commit_hash : string ;
37- snapshot_path : string ;
38- size_on_disk : number ;
36+ commitHash : string ;
37+ snapshotPath : string ;
38+ sizeOnDisk : number ;
3939 readonly files : Set < CachedFileInfo > ;
4040 readonly refs : Set < string > ;
4141
42- last_modified : number ;
42+ lastModified : number ;
4343}
4444
4545export interface CachedRepoInfo {
46- repo_id : string ;
47- repo_type : REPO_TYPE_T ;
48- repo_path : string ;
49- size_on_disk : number ;
50- nb_files : number ;
46+ repoId : string ;
47+ repoType : REPO_TYPE_T ;
48+ repoPath : string ;
49+ sizeOnDisk : number ;
50+ nbFiles : number ;
5151 readonly revisions : Set < CachedRevisionInfo > ;
5252
53- last_accessed : number ;
54- last_modified : number ;
53+ lastAccessed : number ;
54+ lastModified : number ;
5555}
5656
5757export interface HFCacheInfo {
58- size_on_disk : number ;
58+ sizeOnDisk : number ;
5959 readonly repos : Set < CachedRepoInfo > ;
6060 warnings : Error [ ] ;
6161}
6262
63- export async function scan_cache_dir ( cacheDir : string | undefined = undefined ) : Promise < HFCacheInfo > {
63+ export async function scanCacheDir ( cacheDir : string | undefined = undefined ) : Promise < HFCacheInfo > {
6464 if ( ! cacheDir ) cacheDir = HF_HUB_CACHE ;
6565
6666 const s = await stat ( cacheDir ) ;
@@ -88,7 +88,7 @@ export async function scan_cache_dir(cacheDir: string | undefined = undefined):
8888 }
8989
9090 try {
91- const cached = await scan_cached_repo ( absolute ) ;
91+ const cached = await scanCachedRepo ( absolute ) ;
9292 repos . add ( cached ) ;
9393 } catch ( err : unknown ) {
9494 warnings . push ( err as Error ) ;
@@ -97,14 +97,14 @@ export async function scan_cache_dir(cacheDir: string | undefined = undefined):
9797
9898 return {
9999 repos : repos ,
100- size_on_disk : [ ...repos . values ( ) ] . reduce ( ( sum , repo ) => sum + repo . size_on_disk , 0 ) ,
100+ sizeOnDisk : [ ...repos . values ( ) ] . reduce ( ( sum , repo ) => sum + repo . sizeOnDisk , 0 ) ,
101101 warnings : warnings ,
102102 } ;
103103}
104104
105- export async function scan_cached_repo ( repo_path : string ) : Promise < CachedRepoInfo > {
105+ export async function scanCachedRepo ( repoPath : string ) : Promise < CachedRepoInfo > {
106106 // get the directory name
107- const name = basename ( repo_path ) ;
107+ const name = basename ( repoPath ) ;
108108 if ( ! name . includes ( "--" ) ) {
109109 throw new Error ( `Repo path is not a valid HuggingFace cache directory: ${ name } ` ) ;
110110 }
@@ -114,8 +114,8 @@ export async function scan_cached_repo(repo_path: string): Promise<CachedRepoInf
114114 const repoType = parseRepoType ( type ) ;
115115 const repoId = remaining . join ( "/" ) ;
116116
117- const snapshotsPath = join ( repo_path , "snapshots" ) ;
118- const refsPath = join ( repo_path , "refs" ) ;
117+ const snapshotsPath = join ( repoPath , "snapshots" ) ;
118+ const refsPath = join ( repoPath , "refs" ) ;
119119
120120 const snapshotStat = await stat ( snapshotsPath ) ;
121121 if ( ! snapshotStat . isDirectory ( ) ) {
@@ -147,17 +147,15 @@ export async function scan_cached_repo(repo_path: string): Promise<CachedRepoInf
147147 await scanSnapshotDir ( revisionPath , cachedFiles , blobStats ) ;
148148
149149 const revisionLastModified =
150- cachedFiles . size > 0
151- ? Math . max ( ...[ ...cachedFiles ] . map ( ( file ) => file . blob_last_modified ) )
152- : revisionStat . mtimeMs ;
150+ cachedFiles . size > 0 ? Math . max ( ...[ ...cachedFiles ] . map ( ( file ) => file . blobLastModified ) ) : revisionStat . mtimeMs ;
153151
154152 cachedRevisions . add ( {
155- commit_hash : dir ,
153+ commitHash : dir ,
156154 files : cachedFiles ,
157155 refs : refsByHash . get ( dir ) || new Set ( ) ,
158- size_on_disk : [ ...cachedFiles ] . reduce ( ( sum , file ) => sum + file . size_on_disk , 0 ) ,
159- snapshot_path : revisionPath ,
160- last_modified : revisionLastModified ,
156+ sizeOnDisk : [ ...cachedFiles ] . reduce ( ( sum , file ) => sum + file . sizeOnDisk , 0 ) ,
157+ snapshotPath : revisionPath ,
158+ lastModified : revisionLastModified ,
161159 } ) ;
162160
163161 refsByHash . delete ( dir ) ;
@@ -166,11 +164,11 @@ export async function scan_cached_repo(repo_path: string): Promise<CachedRepoInf
166164 // Verify that all refs refer to a valid revision
167165 if ( refsByHash . size > 0 ) {
168166 throw new Error (
169- `Reference(s) refer to missing commit hashes: ${ JSON . stringify ( Object . fromEntries ( refsByHash ) ) } (${ repo_path } )`
167+ `Reference(s) refer to missing commit hashes: ${ JSON . stringify ( Object . fromEntries ( refsByHash ) ) } (${ repoPath } )`
170168 ) ;
171169 }
172170
173- const repoStats = await stat ( repo_path ) ;
171+ const repoStats = await stat ( repoPath ) ;
174172 const repoLastAccessed =
175173 blobStats . size > 0 ? Math . max ( ...[ ...blobStats . values ( ) ] . map ( ( stat ) => stat . atimeMs ) ) : repoStats . atimeMs ;
176174
@@ -179,14 +177,14 @@ export async function scan_cached_repo(repo_path: string): Promise<CachedRepoInf
179177
180178 // Return the constructed CachedRepoInfo object
181179 return {
182- repo_id : repoId ,
183- repo_type : repoType ,
184- repo_path : repo_path ,
185- nb_files : blobStats . size ,
180+ repoId : repoId ,
181+ repoType : repoType ,
182+ repoPath : repoPath ,
183+ nbFiles : blobStats . size ,
186184 revisions : cachedRevisions ,
187- size_on_disk : [ ...blobStats . values ( ) ] . reduce ( ( sum , stat ) => sum + stat . size , 0 ) ,
188- last_accessed : repoLastAccessed ,
189- last_modified : repoLastModified ,
185+ sizeOnDisk : [ ...blobStats . values ( ) ] . reduce ( ( sum , stat ) => sum + stat . size , 0 ) ,
186+ lastAccessed : repoLastAccessed ,
187+ lastModified : repoLastModified ,
190188 } ;
191189}
192190
@@ -219,12 +217,12 @@ export async function scanSnapshotDir(
219217 const blobStat = await getBlobStat ( blobPath , blobStats ) ;
220218
221219 cachedFiles . add ( {
222- file_name : file . name ,
223- file_path : filePath ,
224- blob_path : blobPath ,
225- size_on_disk : blobStat . size ,
226- blob_last_accessed : blobStat . atimeMs ,
227- blob_last_modified : blobStat . mtimeMs ,
220+ filename : file . name ,
221+ filePath : filePath ,
222+ blobPath : blobPath ,
223+ sizeOnDisk : blobStat . size ,
224+ blobLastAccessed : blobStat . atimeMs ,
225+ blobLastModified : blobStat . mtimeMs ,
228226 } ) ;
229227 }
230228}
0 commit comments