@@ -3,6 +3,7 @@ use std::path::Path;
33use  bytes:: Bytes ; 
44
55use  crate :: { 
6+     Progress , 
67    backend:: { FileType ,  FindInBackend ,  decrypt:: DecryptReadBackend } , 
78    blob:: { BlobId ,  BlobType ,  tree:: Tree } , 
89    error:: { ErrorKind ,  RusticError ,  RusticResult } , 
@@ -24,6 +25,7 @@ use crate::{
2425/// * `repo` - The repository to read from. 
2526/// * `tpe` - The type of the file. 
2627/// * `id` - The id of the file. 
28+ ///     * the `id` can **also** be in the `latest` or `latest~N` (with N >= 0) for `tpe=FileType::SnapshotFile` 
2729/// 
2830/// # Errors 
2931/// 
@@ -38,8 +40,17 @@ pub(crate) fn cat_file<P, S: Open>(
3840    repo :  & Repository < P ,  S > , 
3941    tpe :  FileType , 
4042    id :  & str , 
41- )  -> RusticResult < Bytes >  { 
42-     let  id = repo. dbe ( ) . find_id ( tpe,  id) ?; 
43+ )  -> RusticResult < Bytes > 
44+ where 
45+     P :  Progress , 
46+ { 
47+     // For SnapshotFile, using `SnapshotFile::from_str` allows `latest~N` syntax 
48+     let  id = if  let  FileType :: Snapshot  = tpe { 
49+         let  snap_file = SnapshotFile :: from_str ( repo. dbe ( ) ,  id,  |_| true ,  & repo. pb ) ?; 
50+         snap_file. id . into_inner ( ) 
51+     }  else  { 
52+         repo. dbe ( ) . find_id ( tpe,  id) ?
53+     } ; 
4354    let  data = repo. dbe ( ) . read_encrypted_full ( tpe,  & id) ?; 
4455    Ok ( data) 
4556} 
0 commit comments