@@ -1341,17 +1341,64 @@ pub fn is_in_oxen_hidden_dir(path: &Path) -> bool {
1341
1341
false
1342
1342
}
1343
1343
1344
+ // Return canonicalized path if possible, otherwise return original
1345
+ pub fn canonicalize ( path : impl AsRef < Path > ) -> Result < PathBuf , OxenError > {
1346
+ let path = path. as_ref ( ) ;
1347
+ //log::debug!("Path to canonicalize: {path:?}");
1348
+ match dunce:: canonicalize ( path) {
1349
+ Ok ( canon_path) => Ok ( canon_path) ,
1350
+ Err ( err) => Err ( OxenError :: basic_str ( format ! (
1351
+ "path {path:?} cannot be canonicalized due to err {err:?}"
1352
+ ) ) ) ,
1353
+ }
1354
+ }
1355
+
1344
1356
pub fn path_relative_to_dir (
1345
1357
path : impl AsRef < Path > ,
1346
1358
dir : impl AsRef < Path > ,
1347
1359
) -> Result < PathBuf , OxenError > {
1348
- let path = path. as_ref ( ) ;
1349
- let dir = dir. as_ref ( ) ;
1360
+ // Embedded canonicalize calls to catch every case:
1361
+ // -- if both paths can be canonicalized, they both will be
1362
+ // -- if only the dir can be canonicalized, only the dir will be
1363
+ // -- if the dir cannot be canonicalized, neither will be
1364
+ let ( path, dir) = match canonicalize ( & dir) {
1365
+ Ok ( canon_dir) => {
1366
+ /*log::debug!(
1367
+ "dir {:?} canonicalized. Checking path {:?}",
1368
+ dir.as_ref(),
1369
+ path.as_ref()
1370
+ );*/
1371
+ match canonicalize ( & path) {
1372
+ Ok ( canon_path) => ( canon_path, canon_dir) ,
1373
+ // '_' because the debug statement is commented out
1374
+ Err ( _err) => {
1375
+ /*log::debug!(
1376
+ "Err with canonicalization: {err:?}. Returning path {:?} immediately",
1377
+ path.as_ref()
1378
+ );*/
1379
+ return Ok ( path. as_ref ( ) . to_path_buf ( ) ) ;
1380
+ }
1381
+ }
1382
+ }
1383
+ // '_' because the debug statement is commented out
1384
+ Err ( _err) => {
1385
+ /*log::debug!(
1386
+ "Err with canonicalization: {err:?}. Skipping canonicalization of path {:?}",
1387
+ path.as_ref()
1388
+ );*/
1389
+ ( path. as_ref ( ) . to_path_buf ( ) , dir. as_ref ( ) . to_path_buf ( ) )
1390
+ }
1391
+ } ;
1350
1392
1351
- let mut mut_path = path. to_path_buf ( ) ;
1393
+ let mut mut_path = path. clone ( ) ;
1352
1394
let mut components: Vec < PathBuf > = vec ! [ ] ;
1353
1395
while mut_path. parent ( ) . is_some ( ) {
1354
- // println!("Comparing {:?} => {:?} => {:?}", path, mut_path.parent(), dir);
1396
+ /*log::debug!(
1397
+ "Comparing {:?} => {:?} => {:?}",
1398
+ path,
1399
+ mut_path.parent(),
1400
+ dir
1401
+ );*/
1355
1402
if let Some ( filename) = mut_path. file_name ( ) {
1356
1403
if mut_path != dir {
1357
1404
components. push ( PathBuf :: from ( filename) ) ;
0 commit comments