55
66use std;
77use std:: ffi:: OsString ;
8- use std:: fs:: { canonicalize, metadata} ;
98use std:: path:: { Path , PathBuf } ;
109use std:: process:: Command as SysCommand ;
1110
11+ #[ cfg( unix) ]
12+ use std:: fs:: { canonicalize, metadata} ;
13+
14+ #[ cfg( windows) ]
15+ use dunce:: canonicalize;
16+
1217use clap:: parser:: ValuesRef ;
1318use clap:: { Arg , ArgAction , Command } ;
1419use serde_yaml;
@@ -251,7 +256,7 @@ pub fn main() -> Result<()> {
251256 }
252257 None => None ,
253258 } ;
254- std :: os :: unix :: fs :: symlink ( & pkg_path, path) . map_err ( |cause| {
259+ symlink_dir ( & pkg_path, path) . map_err ( |cause| {
255260 Error :: chain (
256261 format ! (
257262 "Failed to create symlink to {:?} at path {:?}." ,
@@ -291,10 +296,21 @@ pub fn main() -> Result<()> {
291296 }
292297}
293298
299+ #[ cfg( target_family = "unix" ) ]
300+ fn symlink_dir ( p : & Path , q : & Path ) -> Result < ( ) > {
301+ Ok ( std:: os:: unix:: fs:: symlink ( p, q) ?)
302+ }
303+
304+ #[ cfg( target_os = "windows" ) ]
305+ fn symlink_dir ( p : & Path , q : & Path ) -> Result < ( ) > {
306+ Ok ( std:: os:: windows:: fs:: symlink_dir ( p, q) ?)
307+ }
308+
294309/// Find the root directory of a package.
295310///
296311/// Traverses the directory hierarchy upwards until a `Bender.yml` file is found.
297312fn find_package_root ( from : & Path ) -> Result < PathBuf > {
313+ #[ cfg( unix) ]
298314 use std:: os:: unix:: fs:: MetadataExt ;
299315
300316 // Canonicalize the path. This will resolve any intermediate links.
@@ -304,7 +320,9 @@ fn find_package_root(from: &Path) -> Result<PathBuf> {
304320
305321 // Look up the device at the current path. This information will then be
306322 // used to stop at filesystem boundaries.
323+ #[ cfg( unix) ]
307324 let limit_rdev: Option < _ > = metadata ( & path) . map ( |m| m. dev ( ) ) . ok ( ) ;
325+ #[ cfg( unix) ]
308326 debugln ! ( "find_package_root: limit rdev = {:?}" , limit_rdev) ;
309327
310328 // Step upwards through the path hierarchy.
@@ -326,13 +344,16 @@ fn find_package_root(from: &Path) -> Result<PathBuf> {
326344 }
327345
328346 // Abort if we have crossed the filesystem boundary.
329- let rdev: Option < _ > = metadata ( & path) . map ( |m| m. dev ( ) ) . ok ( ) ;
330- debugln ! ( "find_package_root: rdev = {:?}" , rdev) ;
331- if rdev != limit_rdev {
332- return Err ( Error :: new ( format ! (
333- "No manifest (`Bender.yml` file) found. Stopped searching at filesystem boundary {:?}." ,
334- tested_path
335- ) ) ) ;
347+ #[ cfg( unix) ]
348+ {
349+ let rdev: Option < _ > = metadata ( & path) . map ( |m| m. dev ( ) ) . ok ( ) ;
350+ debugln ! ( "find_package_root: rdev = {:?}" , rdev) ;
351+ if rdev != limit_rdev {
352+ return Err ( Error :: new ( format ! (
353+ "No manifest (`Bender.yml` file) found. Stopped searching at filesystem boundary {:?}." ,
354+ tested_path
355+ ) ) ) ;
356+ }
336357 }
337358 }
338359
@@ -358,7 +379,9 @@ pub fn read_manifest(path: &Path) -> Result<Manifest> {
358379
359380/// Load a configuration by traversing a directory hierarchy upwards.
360381fn load_config ( from : & Path ) -> Result < Config > {
382+ #[ cfg( unix) ]
361383 use std:: os:: unix:: fs:: MetadataExt ;
384+
362385 let mut out = PartialConfig :: new ( ) ;
363386
364387 // Canonicalize the path. This will resolve any intermediate links.
@@ -368,7 +391,9 @@ fn load_config(from: &Path) -> Result<Config> {
368391
369392 // Look up the device at the current path. This information will then be
370393 // used to stop at filesystem boundaries.
394+ #[ cfg( unix) ]
371395 let limit_rdev: Option < _ > = metadata ( & path) . map ( |m| m. dev ( ) ) . ok ( ) ;
396+ #[ cfg( unix) ]
372397 debugln ! ( "load_config: limit rdev = {:?}" , limit_rdev) ;
373398
374399 // Step upwards through the path hierarchy.
@@ -390,10 +415,13 @@ fn load_config(from: &Path) -> Result<Config> {
390415 }
391416
392417 // Abort if we have crossed the filesystem boundary.
393- let rdev: Option < _ > = metadata ( & path) . map ( |m| m. dev ( ) ) . ok ( ) ;
394- debugln ! ( "load_config: rdev = {:?}" , rdev) ;
395- if rdev != limit_rdev {
396- break ;
418+ #[ cfg( unix) ]
419+ {
420+ let rdev: Option < _ > = metadata ( & path) . map ( |m| m. dev ( ) ) . ok ( ) ;
421+ debugln ! ( "load_config: rdev = {:?}" , rdev) ;
422+ if rdev != limit_rdev {
423+ break ;
424+ }
397425 }
398426 }
399427
0 commit comments