Build even when broken symlinks are present

Better resolution to #1396
This commit is contained in:
Mark Owen 2022-12-05 12:26:58 -07:00
parent 4deb5c7cee
commit 8008fe4b16
1 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,5 @@
use crate::errors::*; use crate::errors::*;
use log::{debug, trace}; use log::{debug, info, trace};
use std::convert::Into; use std::convert::Into;
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::Write; use std::io::Write;
@ -113,7 +113,13 @@ pub fn copy_files_except_ext(
let entry = entry?; let entry = entry?;
let metadata = entry let metadata = entry
.path() .path()
// Attempt to read metadata of symlink target
.metadata() .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()))?; .with_context(|| format!("Failed to read {:?}", entry.path()))?;
// If the entry is a dir and the recursive option is enabled, call itself // If the entry is a dir and the recursive option is enabled, call itself
@ -238,6 +244,12 @@ mod tests {
) { ) {
panic!("Could not symlink file.png: {}", err); 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 // Create output dir
if let Err(err) = fs::create_dir(&tmp.path().join("output")) { if let Err(err) = fs::create_dir(&tmp.path().join("output")) {