Skip to content

Build even when broken symlinks are present #1944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/utils/fs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::errors::*;
use log::{debug, trace};
use log::{debug, info, trace};
use std::convert::Into;
use std::fs::{self, File};
use std::io::Write;
Expand Down Expand Up @@ -113,7 +113,13 @@ pub fn copy_files_except_ext(
let entry = entry?;
let metadata = entry
.path()
// Attempt to read metadata of symlink target
.metadata()
// Handle broken symlinks by reading the symlink metadata directly (not the symlink target metadata)
.or_else(|_| {
info!("Failed to read file metadata of {:?}. Attempting to read metadata without traversing symlinks.", entry.path());
entry.path().symlink_metadata()
})
.with_context(|| format!("Failed to read {:?}", entry.path()))?;

// If the entry is a dir and the recursive option is enabled, call itself
Expand Down Expand Up @@ -238,6 +244,12 @@ mod tests {
) {
panic!("Could not symlink file.png: {}", err);
}
if let Err(err) = symlink(
&tmp.path().join("missing_file.txt"),
&tmp.path().join("missing_symlink.txt"),
) {
panic!("Could not symlink missing_file.txt: {}", err);
}

// Create output dir
if let Err(err) = fs::create_dir(&tmp.path().join("output")) {
Expand Down