Engineering a website + blog: Fixes

Engineering a website + blog: Fixes - directory traversal fix

Categories

Website

Tags

Rust

Published on: 2018-06-22

Word count: 51

Estimated reading time: 1 minute

Engineering a website + blog: Fixes

This post is about a small fix I made regarding directory traversal in the importer.

Previously used filter which excluded traversing directories. Checking inside the loop rather we have a file or directory solves this issue:

    for entry in WalkDir::new(path).min_depth(1).into_iter() {
        if entry.is_err() {
            println!("Failed traversing file: {}", entry.unwrap_err());
            continue;
        }

        let entry = entry.unwrap();
        if entry.file_type().is_dir() {
            continue;
        }

This ensures we properly handle directory traversal and file processing.