Merge pull request #1323 from iffyio/copy-symlinks
Resolve full file paths when copying files
This commit is contained in:
commit
db8a2821ea
|
@ -110,7 +110,7 @@ pub fn copy_files_except_ext(
|
||||||
|
|
||||||
for entry in fs::read_dir(from)? {
|
for entry in fs::read_dir(from)? {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let metadata = entry.metadata()?;
|
let metadata = entry.path().metadata()?;
|
||||||
|
|
||||||
// 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
|
||||||
if metadata.is_dir() && recursive {
|
if metadata.is_dir() && recursive {
|
||||||
|
@ -187,7 +187,17 @@ pub fn get_404_output_file(input_404: &Option<String>) -> String {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::copy_files_except_ext;
|
use super::copy_files_except_ext;
|
||||||
use std::fs;
|
use std::{fs, io::Result, path::Path};
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> Result<()> {
|
||||||
|
std::os::windows::fs::symlink_file(src, dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> Result<()> {
|
||||||
|
std::os::unix::fs::symlink(src, dst)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn copy_files_except_ext_test() {
|
fn copy_files_except_ext_test() {
|
||||||
|
@ -218,6 +228,12 @@ mod tests {
|
||||||
if let Err(err) = fs::File::create(&tmp.path().join("sub_dir_exists/file.txt")) {
|
if let Err(err) = fs::File::create(&tmp.path().join("sub_dir_exists/file.txt")) {
|
||||||
panic!("Could not create sub_dir_exists/file.txt: {}", err);
|
panic!("Could not create sub_dir_exists/file.txt: {}", err);
|
||||||
}
|
}
|
||||||
|
if let Err(err) = symlink(
|
||||||
|
&tmp.path().join("file.png"),
|
||||||
|
&tmp.path().join("symlink.png"),
|
||||||
|
) {
|
||||||
|
panic!("Could not symlink file.png: {}", 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")) {
|
||||||
|
@ -249,5 +265,8 @@ mod tests {
|
||||||
if !(&tmp.path().join("output/sub_dir_exists/file.txt")).exists() {
|
if !(&tmp.path().join("output/sub_dir_exists/file.txt")).exists() {
|
||||||
panic!("output/sub_dir/file.png should exist")
|
panic!("output/sub_dir/file.png should exist")
|
||||||
}
|
}
|
||||||
|
if !(&tmp.path().join("output/symlink.png")).exists() {
|
||||||
|
panic!("output/symlink.png should exist")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue