Skip to content
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

Follow symbolic links when walking directories #415

Merged
merged 1 commit into from
Jan 16, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions src/highlighting/theme_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::settings::*;
use super::super::LoadingError;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use walkdir::WalkDir;

#[derive(Debug, Default, Serialize, Deserialize)]
pub struct ThemeSet {
Expand All @@ -23,7 +22,7 @@ impl ThemeSet {
/// This is god for enumerating before loading one with [`get_theme`](#method.get_theme)
pub fn discover_theme_paths<P: AsRef<Path>>(folder: P) -> Result<Vec<PathBuf>, LoadingError> {
let mut themes = Vec::new();
for entry in WalkDir::new(folder) {
for entry in crate::utils::walk_dir(folder) {
let entry = entry.map_err(LoadingError::WalkDir)?;
if entry.path().extension().map_or(false, |e| e == "tmTheme") {
themes.push(entry.path().to_owned());
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub mod highlighting;
pub mod html;
pub mod parsing;
pub mod util;
mod utils;

use std::io::Error as IoError;
use std::error::Error;
Expand Down
4 changes: 1 addition & 3 deletions src/parsing/syntax_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use super::super::LoadingError;

use std::collections::{HashMap, HashSet, BTreeSet};
use std::path::Path;
#[cfg(feature = "yaml-load")]
use walkdir::WalkDir;
use std::io::{self, BufRead, BufReader};
use std::fs::File;
use std::mem;
Expand Down Expand Up @@ -479,7 +477,7 @@ impl SyntaxSetBuilder {
folder: P,
lines_include_newline: bool
) -> Result<(), LoadingError> {
for entry in WalkDir::new(folder).sort_by(|a, b| a.file_name().cmp(b.file_name())) {
for entry in crate::utils::walk_dir(folder).sort_by(|a, b| a.file_name().cmp(b.file_name())) {
let entry = entry.map_err(LoadingError::WalkDir)?;
if entry.path().extension().map_or(false, |e| e == "sublime-syntax") {
let syntax = load_syntax_file(entry.path(), lines_include_newline)?;
Expand Down
11 changes: 11 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! Private library utilities that are not exposed to clients since we don't
//! want to make semver guarantees about them

use std::path::Path;

use walkdir::WalkDir;

/// Private helper to walk a dir and also follow symbolic links.
pub fn walk_dir<P: AsRef<Path>>(folder: P) -> WalkDir {
WalkDir::new(folder).follow_links(true)
}