]> git.proxmox.com Git - cargo.git/commitdiff
Check if symlinks are directories
authorThom Wiggers <thom@thomwiggers.nl>
Wed, 3 Apr 2019 13:07:04 +0000 (15:07 +0200)
committerThom Wiggers <thom@thomwiggers.nl>
Tue, 30 Jul 2019 07:31:35 +0000 (09:31 +0200)
Fixes #2748.

Uses @ehuss's suggested fix.
See https://github.com/rust-lang/cargo/pull/6817#issuecomment-480538976

src/cargo/sources/path.rs
tests/testsuite/package.rs

index af6d458c345a460ee4dcfe3b1bb284d15c45a3e9..db8e7d998766a506094569f7b519d66493483224 100644 (file)
@@ -219,9 +219,17 @@ impl<'cfg> PathSource<'cfg> {
         // the untracked files are often part of a build and may become relevant
         // as part of a future commit.
         let index_files = index.iter().map(|entry| {
-            use libgit2_sys::GIT_FILEMODE_COMMIT;
-            let is_dir = entry.mode == GIT_FILEMODE_COMMIT as u32;
-            (join(root, &entry.path), Some(is_dir))
+            use libgit2_sys::{GIT_FILEMODE_COMMIT, GIT_FILEMODE_LINK};
+            // ``is_dir`` is an optimization to avoid calling
+            // ``fs::metadata`` on every file.
+            let is_dir = if entry.mode == GIT_FILEMODE_LINK as u32 {
+                // Let the code below figure out if this symbolic link points
+                // to a directory or not.
+                None
+            } else {
+                Some(entry.mode == GIT_FILEMODE_COMMIT as u32)
+            };
+            (join(root, &entry.path), is_dir)
         });
         let mut opts = git2::StatusOptions::new();
         opts.include_untracked(true);
index 71afb01f9d6676d5c96f00966641a452af10f841..d895dca7812a06fc77459132fe56f008ef3b01fa 100644 (file)
@@ -506,10 +506,14 @@ fn package_git_submodule() {
 
 #[cargo_test]
 fn package_symlink_to_submodule() {
+    #[cfg(unix)]
+    use std::os::unix::fs::symlink as symlink;
+    #[cfg(windows)]
+    use std::os::unix::fs::symlink_dir as symlink;
+
     let project = git::new("foo", |project| {
         project
             .file("src/lib.rs", "pub fn foo() {}")
-            .symlink("submodule", "submodule-link")
         }).unwrap();
 
     let library = git::new("submodule", |library| {
@@ -519,6 +523,8 @@ fn package_symlink_to_submodule() {
     let repository = git2::Repository::open(&project.root()).unwrap();
     let url = path2url(library.root()).to_string();
     git::add_submodule(&repository, &url, Path::new("submodule"));
+    t!(symlink(&project.root().join("submodule"), &project.root().join("submodule-link")));
+    git::add(&repository);
     git::commit(&repository);
 
     let repository = git2::Repository::open(&project.root().join("submodule")).unwrap();