@@ -1438,30 +1438,27 @@ impl FileSystemPath {
14381438 ) )
14391439 }
14401440
1441- /// Similar to [FileSystemPath::join], but returns an Option that will be
1442- /// None when the joined path would leave the filesystem root.
1441+ /// Similar to [FileSystemPath::join], but returns an [` Option`] that will be [`None`] when the
1442+ /// joined path would leave the filesystem root.
14431443 #[ allow( clippy:: needless_borrow) ] // for windows build
1444- pub fn try_join ( & self , path : & str ) -> Result < Option < FileSystemPath > > {
1444+ pub fn try_join ( & self , path : & str ) -> Option < FileSystemPath > {
14451445 // TODO(PACK-3279): Remove this once we do not produce invalid paths at the first place.
14461446 #[ cfg( target_os = "windows" ) ]
14471447 let path = path. replace ( '\\' , "/" ) ;
14481448
1449- if let Some ( path) = join_path ( & self . path , & path) {
1450- Ok ( Some ( Self :: new_normalized ( self . fs , path. into ( ) ) ) )
1451- } else {
1452- Ok ( None )
1453- }
1449+ join_path ( & self . path , & path) . map ( |p| Self :: new_normalized ( self . fs , RcStr :: from ( p) ) )
14541450 }
14551451
1456- /// Similar to [FileSystemPath::join], but returns an Option that will be
1457- /// None when the joined path would leave the current path.
1458- pub fn try_join_inside ( & self , path : & str ) -> Result < Option < FileSystemPath > > {
1459- if let Some ( path) = join_path ( & self . path , path)
1460- && path. starts_with ( & * self . path )
1452+ /// Similar to [FileSystemPath::try_join], but returns [`None`] when the new path would leave
1453+ /// the current path (not just the filesystem root). This is useful for preventing access
1454+ /// outside of a directory.
1455+ pub fn try_join_inside ( & self , path : & str ) -> Option < FileSystemPath > {
1456+ if let Some ( p) = join_path ( & self . path , path)
1457+ && p. starts_with ( & * self . path )
14611458 {
1462- return Ok ( Some ( Self :: new_normalized ( self . fs , path . into ( ) ) ) ) ;
1459+ return Some ( Self :: new_normalized ( self . fs , RcStr :: from ( p ) ) ) ;
14631460 }
1464- Ok ( None )
1461+ None
14651462 }
14661463
14671464 /// DETERMINISM: Result is in random order. Either sort result or do not depend
0 commit comments