1
1
use bstr:: ByteSlice ;
2
+ use gix_fs:: stack:: ToNormalPathComponents ;
2
3
3
4
use crate :: {
4
5
bstr:: { BStr , BString } ,
@@ -380,18 +381,29 @@ impl std::ops::Index<std::ops::RangeTo<usize>> for RepositoryPathPuf {
380
381
381
382
///
382
383
pub mod repository_path_buf {
384
+ use gix_fs:: stack:: to_normal_path_components;
385
+
383
386
/// The error used in [`RepositoryPathPuf`](super::RepositoryPathPuf).
384
387
#[ derive( Debug , thiserror:: Error ) ]
385
388
#[ allow( missing_docs) ]
386
- pub enum Error { }
389
+ pub enum Error {
390
+ #[ error( transparent) ]
391
+ ContainsNonNormalComponents ( #[ from] to_normal_path_components:: Error ) ,
392
+ #[ error( transparent) ]
393
+ IllegalUtf8 ( #[ from] gix_path:: Utf8Error ) ,
394
+ }
387
395
}
388
396
389
397
impl TryFrom < & str > for RepositoryPathPuf {
390
398
type Error = repository_path_buf:: Error ;
391
399
392
400
fn try_from ( value : & str ) -> Result < Self , Self :: Error > {
393
- // TODO
394
- // Check whether the documented constraints are met, return `Err` if not.
401
+ let path = std:: path:: Path :: new ( value) ;
402
+
403
+ for component in path. to_normal_path_components ( ) {
404
+ component?;
405
+ }
406
+
395
407
Ok ( Self { inner : value. into ( ) } )
396
408
}
397
409
}
@@ -400,8 +412,12 @@ impl TryFrom<&BStr> for RepositoryPathPuf {
400
412
type Error = repository_path_buf:: Error ;
401
413
402
414
fn try_from ( value : & BStr ) -> Result < Self , Self :: Error > {
403
- // TODO
404
- // Check whether the documented constraints are met, return `Err` if not.
415
+ let path: & std:: path:: Path = & gix_path:: try_from_bstr ( value) ?;
416
+
417
+ for component in path. to_normal_path_components ( ) {
418
+ component?;
419
+ }
420
+
405
421
Ok ( Self { inner : value. into ( ) } )
406
422
}
407
423
}
@@ -410,8 +426,12 @@ impl TryFrom<BString> for RepositoryPathPuf {
410
426
type Error = repository_path_buf:: Error ;
411
427
412
428
fn try_from ( value : BString ) -> Result < Self , Self :: Error > {
413
- // TODO
414
- // Check whether the documented constraints are met, return `Err` if not.
429
+ let path: & std:: path:: Path = & gix_path:: try_from_bstr ( & value) ?;
430
+
431
+ for component in path. to_normal_path_components ( ) {
432
+ component?;
433
+ }
434
+
415
435
Ok ( Self { inner : value } )
416
436
}
417
437
}
0 commit comments