globwalk-0.8.1/.cargo_vcs_info.json0000644000000001121376377105300127100ustar { "git": { "sha1": "ef95cfb646e8823ffdbb7e3913a1ab8fe121cc48" } } globwalk-0.8.1/.gitignore010064400017500001750000000000701376375613200135050ustar 00000000000000.idea/ cmake-build-debug/ /target **/*.rs.bk Cargo.lock globwalk-0.8.1/.travis.yml010064400017500001750000000014251376375625100136350ustar 00000000000000sudo: false language: rust rust: - 1.31.0 # Oldest supported - stable - beta - nightly matrix: include: - env: RUSTFMT rust: 1.31.0 # `stable`: Locking down for consistent behavior install: - rustup component add rustfmt-preview script: - cargo fmt -- --check - env: RUSTFLAGS="-D warnings" rust: 1.31.0 # `stable`: Locking down for consistent behavior script: - cargo check --tests - env: CLIPPY rust: 1.41.0 install: - rustup component add clippy script: - cargo clippy --all-features -- -D clippy::all allow_failures: - rust: nightly fast_finish: true install: - rustc -Vv - cargo -V script: - rm -rf target/debug/deps/*globwalk* # Avoid rustdoc problems - cargo test --verbose cache: cargo: true globwalk-0.8.1/Cargo.lock0000644000000351601376377105300106760ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] name = "aho-corasick" version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "memchr 2.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "autocfg" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "backtrace" version = "0.3.35" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace-sys 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.81 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "backtrace-sys" version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.81 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bstr" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "memchr 2.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cc" version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "crossbeam-utils" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "docmatic" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "failure" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "fuchsia-cprng" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "globset" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)", "bstr 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "globwalk" version = "0.8.1" dependencies = [ "backtrace 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "docmatic 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "ignore 0.4.17 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ignore" version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "globset 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "log" version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "memchr" version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rand" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.81 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_core" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rdrand" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex" version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "regex-syntax 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", "thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex-syntax" version = "0.6.21" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "remove_dir_all" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-demangle" version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "same-file" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tempdir" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "remove_dir_all 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "thread_local" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "walkdir" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "which" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "failure 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.81 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi-util" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum aho-corasick 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" "checksum autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" "checksum backtrace 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)" = "1371048253fa3bac6704bfd6bbfc922ee9bdcee8881330d40f308b81cc5adc55" "checksum backtrace-sys 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "18fbebbe1c9d1f383a9cc7e8ccdb471b91c8d024ee9c2ca5b5346121fe8b4399" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum bstr 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "473fc6b38233f9af7baa94fb5852dca389e3d95b8e21c8e3719301462c5d9faf" "checksum cc 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)" = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" "checksum crossbeam-utils 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" "checksum docmatic 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8d58ebceaf539cb79420fb3046da9396e11021c536ae953be6ba5363842da8c3" "checksum failure 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" "checksum fnv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum globset 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c152169ef1e421390738366d2f796655fec62621dabbd0fd476f905934061e4a" "checksum ignore 0.4.17 (registry+https://github.com/rust-lang/crates.io-index)" = "b287fb45c60bb826a0dc68ff08742b9d88a2fea13d6e0c286b3172065aaf878c" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum libc 0.2.81 (registry+https://github.com/rust-lang/crates.io-index)" = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" "checksum log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" "checksum memchr 2.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" "checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum regex 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c" "checksum regex-syntax 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)" = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" "checksum remove_dir_all 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" "checksum rustc-demangle 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" "checksum same-file 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" "checksum walkdir 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" "checksum which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b57acb10231b9493c8472b20cb57317d0679a49e0bdbee44b3b803a6473af164" "checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" globwalk-0.8.1/Cargo.toml0000644000000022751376377105300107220ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "globwalk" version = "0.8.1" authors = ["Gilad Naaman "] description = "Glob-matched recursive file system walking." readme = "README.md" keywords = ["regex", "glob", "pattern", "walk", "iterator"] categories = ["filesystem"] license = "MIT" repository = "https://github.com/gilnaa/globwalk" [dependencies.bitflags] version = "1.2" [dependencies.ignore] version = "0.4.11" [dependencies.walkdir] version = "2" [dev-dependencies.backtrace] version = "=0.3.35" [dev-dependencies.docmatic] version = "0.1.2" [dev-dependencies.tempdir] version = "0.3.6" [badges.appveyor] repository = "Gilnaa/globwalk" [badges.travis-ci] repository = "Gilnaa/globwalk" globwalk-0.8.1/Cargo.toml.orig010064400017500001750000000013351376375620700144140ustar 00000000000000[package] name = "globwalk" version = "0.8.1" description = "Glob-matched recursive file system walking." authors = ["Gilad Naaman "] readme = "README.md" license = "MIT" repository = "https://github.com/gilnaa/globwalk" categories = ["filesystem"] keywords = ["regex", "glob", "pattern", "walk", "iterator"] [badges] travis-ci = { repository = "Gilnaa/globwalk" } appveyor = { repository = "Gilnaa/globwalk" } [dependencies] walkdir = "2" ignore = "0.4.11" bitflags = "1.2" [dev-dependencies] tempdir = "0.3.6" docmatic = "0.1.2" # We're not using backtrace, really. It is just a deep dependency of docmatic. # Locking down its version so that we can compile the tests using rustc 1.31.0 backtrace = "=0.3.35" globwalk-0.8.1/LICENSE010064400017500001750000000020371376375613200125270ustar 00000000000000Copyright (c) 2017 Gilad Naaman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.globwalk-0.8.1/README.md010064400017500001750000000027631376375671500130160ustar 00000000000000# GlobWalk # [![Build Status](https://travis-ci.org/Gilnaa/globwalk.svg?branch=master)](https://travis-ci.org/Gilnaa/globwalk) [![Build status](https://ci.appveyor.com/api/projects/status/81rkf5lcyt1ouh9n/branch/master?svg=true)](https://ci.appveyor.com/project/Gilnaa/globwalk) [![](https://docs.rs/globwalk/badge.svg)](https://docs.rs/globwalk/) ![License](https://img.shields.io/crates/l/globwalk.svg) [![crates.io](https://img.shields.io/crates/v/globwalk.svg)](https://crates.io/crates/globwalk) Recursively find files in a directory using globs. Based on both `walkdir` & `ignore` (❤), this crate inherits many goodies from both, such as limiting search depth and amount of open file descriptors. Licensed under MIT. ### Why not `glob` ### - The `glob` crate does not support having `{a,b}` in patterns. - `globwalk` can match several glob-patterns at the same time. - `globwalk` supports excluding results with `!`. - `glob` searches for files in the current working directory, whereas `globwalk` starts at a specified base-dir. ### Usage ### To use this crate, add `globwalk` as a dependency to your project's `Cargo.toml`: ```toml [dependencies] globwalk = "0.8.1" ``` The following piece of code recursively find all `png`, `jpg`, or `gif` files: ```rust extern crate globwalk; use std::fs; for img in globwalk::glob("*.{png,jpg,gif}").unwrap() { if let Ok(img) = img { println!("{:?}", img.path()); } } ``` See the [documentation](https://docs.rs/globwalk/) for more details. globwalk-0.8.1/appveyor.yml010064400017500001750000000106101376375613200141060ustar 00000000000000# Appveyor configuration template for Rust using rustup for Rust installation # https://github.com/starkat99/appveyor-rust ## Operating System (VM environment) ## # Rust needs at least Visual Studio 2013 Appveyor OS for MSVC targets. os: Visual Studio 2015 ## Build Matrix ## # This configuration will setup a build for each channel & target combination (12 windows # combinations in all). # # There are 3 channels: stable, beta, and nightly. # # Alternatively, the full version may be specified for the channel to build using that specific # version (e.g. channel: 1.5.0) # # The values for target are the set of windows Rust build targets. Each value is of the form # # ARCH-pc-windows-TOOLCHAIN # # Where ARCH is the target architecture, either x86_64 or i686, and TOOLCHAIN is the linker # toolchain to use, either msvc or gnu. See https://www.rust-lang.org/downloads.html#win-foot for # a description of the toolchain differences. # See https://github.com/rust-lang-nursery/rustup.rs/#toolchain-specification for description of # toolchains and host triples. # # Comment out channel/target combos you do not wish to build in CI. # # You may use the `cargoflags` and `RUSTFLAGS` variables to set additional flags for cargo commands # and rustc, respectively. For instance, you can uncomment the cargoflags lines in the nightly # channels to enable unstable features when building for nightly. Or you could add additional # matrix entries to test different combinations of features. environment: matrix: ### MSVC Toolchains ### # Stable 64-bit MSVC - channel: stable target: x86_64-pc-windows-msvc # Stable 32-bit MSVC - channel: stable target: i686-pc-windows-msvc # Beta 64-bit MSVC - channel: beta target: x86_64-pc-windows-msvc # Beta 32-bit MSVC - channel: beta target: i686-pc-windows-msvc # Nightly 64-bit MSVC - channel: nightly target: x86_64-pc-windows-msvc #cargoflags: --features "unstable" # Nightly 32-bit MSVC - channel: nightly target: i686-pc-windows-msvc #cargoflags: --features "unstable" # Note: Disabled these targets due to linking errors I have no time to fix. #### GNU Toolchains ### # # # Stable 64-bit GNU # - channel: stable # target: x86_64-pc-windows-gnu # # Stable 32-bit GNU # - channel: stable # target: i686-pc-windows-gnu # # Beta 64-bit GNU # - channel: beta # target: x86_64-pc-windows-gnu # # Beta 32-bit GNU # - channel: beta # target: i686-pc-windows-gnu # # Nightly 64-bit GNU # - channel: nightly # target: x86_64-pc-windows-gnu # #cargoflags: --features "unstable" # # Nightly 32-bit GNU # - channel: nightly # target: i686-pc-windows-gnu # #cargoflags: --features "unstable" ### Allowed failures ### # See Appveyor documentation for specific details. In short, place any channel or targets you wish # to allow build failures on (usually nightly at least is a wise choice). This will prevent a build # or test failure in the matching channels/targets from failing the entire build. matrix: allow_failures: - channel: nightly # If you only care about stable channel build failures, uncomment the following line: #- channel: beta ## Install Script ## # This is the most important part of the Appveyor configuration. This installs the version of Rust # specified by the 'channel' and 'target' environment variables from the build matrix. This uses # rustup to install Rust. # # For simple configurations, instead of using the build matrix, you can simply set the # default-toolchain and default-host manually here. install: - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe - rustup-init -yv --default-toolchain %channel% --default-host %target% - set PATH=%PATH%;%USERPROFILE%\.cargo\bin - if "%TARGET%" == "i686-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw32\bin - if "%TARGET%" == "x86_64-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw64\bin - rustc -vV - cargo -vV ## Build Script ## # 'cargo test' takes care of building for us, so disable Appveyor's build stage. This prevents # the "directory does not contain a project or solution file" error. build: false # Uses 'cargo test' to run tests and build. Alternatively, the project may call compiled programs #directly or perform other testing commands. Rust will automatically be placed in the PATH # environment variable. test_script: - cargo test --verbose %cargoflags% globwalk-0.8.1/examples/list.rs010064400017500001750000000026111376375613200146570ustar 00000000000000// Copyright (c) 2018 Gilad Naaman // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. extern crate globwalk; use globwalk::GlobWalkerBuilder; use std::env::args; fn main() { let patterns = args().skip(1).collect::>(); for f in GlobWalkerBuilder::from_patterns(".", &patterns[..]) .build() .unwrap() { println!("{:?}", f.unwrap().path()); } } globwalk-0.8.1/src/doctests.rs010064400017500001750000000007611376375613200145110ustar 00000000000000extern crate tempdir; use std::error::Error; use std::fs::{File, create_dir_all}; use std::path::PathBuf; use tempdir::TempDir; fn create_files(files: &[&str]) -> Result> { let tmp_dir = TempDir::new("globwalk")?; for f in files { let file_path = PathBuf::from(f); if let Some(dir) = file_path.parent() { create_dir_all(tmp_dir.path().join(dir))?; } File::create(tmp_dir.path().join(file_path))?; } Ok(tmp_dir) } globwalk-0.8.1/src/lib.rs010064400017500001750000000667531376377104100134400ustar 00000000000000// Copyright (c) 2017 Gilad Naaman // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. //! Recursively find files in a directory using globs. //! //! Features include //! - [`gitignore`'s extended glob syntax][gitignore] //! - Control over symlink behavior //! - Control depth walked //! - Control order results are returned //! //! [gitignore]: https://git-scm.com/docs/gitignore#_pattern_format //! //! # Examples //! //! ## Finding image files in the current directory. //! //! ```rust //! extern crate globwalk; //! # include!("doctests.rs"); //! //! use std::fs; //! # fn run() -> Result<(), Box<::std::error::Error>> { //! # let temp_dir = create_files(&["cow.jog", "cat.gif"])?; //! # ::std::env::set_current_dir(&temp_dir)?; //! //! for img in globwalk::glob("*.{png,jpg,gif}")? { //! if let Ok(img) = img { //! fs::remove_file(img.path())?; //! } //! } //! # Ok(()) } //! # fn main() { run().unwrap() } //! ``` //! //! ## Advanced Globbing ### //! //! By using one of the constructors of `globwalk::GlobWalker`, it is possible to alter the //! base-directory or add multiple patterns. //! //! ```rust //! extern crate globwalk; //! # include!("doctests.rs"); //! //! use std::fs; //! //! # fn run() -> Result<(), Box<::std::error::Error>> { //! # let temp_dir = create_files(&["cow.jog", "cat.gif"])?; //! # let BASE_DIR = &temp_dir; //! let walker = globwalk::GlobWalkerBuilder::from_patterns( //! BASE_DIR, //! &["*.{png,jpg,gif}", "!Pictures/*"], //! ) //! .max_depth(4) //! .follow_links(true) //! .build()? //! .into_iter() //! .filter_map(Result::ok); //! //! for img in walker { //! fs::remove_file(img.path())?; //! } //! # Ok(()) } //! # fn main() { run().unwrap() } //! ``` // Our doctests need main to compile; AFAICT this is a false positive generated by clippy #![allow(clippy::needless_doctest_main)] #![warn(missing_docs)] extern crate ignore; extern crate walkdir; extern crate bitflags; #[cfg(test)] extern crate tempdir; use ignore::overrides::{Override, OverrideBuilder}; use ignore::Match; use std::cmp::Ordering; use std::path::Path; use std::path::PathBuf; use walkdir::WalkDir; /// Error from parsing globs. #[derive(Debug)] pub struct GlobError(ignore::Error); /// Error from iterating on files. pub type WalkError = walkdir::Error; /// A directory entry. /// /// This is the type of value that is yielded from the iterators defined in this crate. pub type DirEntry = walkdir::DirEntry; impl From for GlobError { fn from(e: std::io::Error) -> Self { GlobError(e.into()) } } impl From for std::io::Error { fn from(e: GlobError) -> Self { if let ignore::Error::Io(e) = e.0 { e } else { std::io::ErrorKind::Other.into() } } } impl std::fmt::Display for GlobError { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { self.0.fmt(f) } } impl std::error::Error for GlobError { fn description(&self) -> &str { self.0.description() } } bitflags::bitflags! { /// Possible file type filters. /// Constants can be OR'd to filter for several types at a time. /// /// Note that not all files are represented in this enum. /// For example, a char-device is neither a file, a directory, nor a symlink. pub struct FileType: u32 { #[allow(missing_docs)] const FILE = 0b001; #[allow(missing_docs)] const DIR = 0b010; #[allow(missing_docs)] const SYMLINK = 0b100; } } /// An iterator for recursively yielding glob matches. /// /// The order of elements yielded by this iterator is unspecified. pub struct GlobWalkerBuilder { root: PathBuf, patterns: Vec, walker: WalkDir, case_insensitive: bool, file_type: Option, } impl GlobWalkerBuilder { /// Construct a new `GlobWalker` with a glob pattern. /// /// When iterated, the `base` directory will be recursively searched for paths /// matching `pattern`. pub fn new(base: P, pattern: S) -> Self where P: AsRef, S: AsRef, { GlobWalkerBuilder::from_patterns(base, &[pattern]) } /// Construct a new `GlobWalker` from a list of patterns. /// /// When iterated, the `base` directory will be recursively searched for paths /// matching `patterns`. pub fn from_patterns(base: P, patterns: &[S]) -> Self where P: AsRef, S: AsRef, { fn normalize_pattern>(pattern: S) -> String { // Either `ignore` or our iteration code treat a single asterisk pretty strangely, matching everything, even // paths that are inside a sub-direcrtory. if pattern.as_ref() == "*" { String::from("/*") } else { pattern.as_ref().to_owned() } } GlobWalkerBuilder { root: base.as_ref().into(), patterns: patterns.iter().map(normalize_pattern).collect::<_>(), walker: WalkDir::new(base), case_insensitive: false, file_type: None, } } /// Set the minimum depth of entries yielded by the iterator. /// /// The smallest depth is `0` and always corresponds to the path given /// to the `new` function on this type. Its direct descendents have depth /// `1`, and their descendents have depth `2`, and so on. pub fn min_depth(mut self, depth: usize) -> Self { self.walker = self.walker.min_depth(depth); self } /// Set the maximum depth of entries yield by the iterator. /// /// The smallest depth is `0` and always corresponds to the path given /// to the `new` function on this type. Its direct descendents have depth /// `1`, and their descendents have depth `2`, and so on. /// /// Note that this will not simply filter the entries of the iterator, but /// it will actually avoid descending into directories when the depth is /// exceeded. pub fn max_depth(mut self, depth: usize) -> Self { self.walker = self.walker.max_depth(depth); self } /// Follow symbolic links. By default, this is disabled. /// /// When `yes` is `true`, symbolic links are followed as if they were /// normal directories and files. If a symbolic link is broken or is /// involved in a loop, an error is yielded. /// /// When enabled, the yielded [`DirEntry`] values represent the target of /// the link while the path corresponds to the link. See the [`DirEntry`] /// type for more details. /// /// [`DirEntry`]: struct.DirEntry.html pub fn follow_links(mut self, yes: bool) -> Self { self.walker = self.walker.follow_links(yes); self } /// Set the maximum number of simultaneously open file descriptors used /// by the iterator. /// /// `n` must be greater than or equal to `1`. If `n` is `0`, then it is set /// to `1` automatically. If this is not set, then it defaults to some /// reasonably low number. /// /// This setting has no impact on the results yielded by the iterator /// (even when `n` is `1`). Instead, this setting represents a trade off /// between scarce resources (file descriptors) and memory. Namely, when /// the maximum number of file descriptors is reached and a new directory /// needs to be opened to continue iteration, then a previous directory /// handle is closed and has its unyielded entries stored in memory. In /// practice, this is a satisfying trade off because it scales with respect /// to the *depth* of your file tree. Therefore, low values (even `1`) are /// acceptable. /// /// Note that this value does not impact the number of system calls made by /// an exhausted iterator. /// /// # Platform behavior /// /// On Windows, if `follow_links` is enabled, then this limit is not /// respected. In particular, the maximum number of file descriptors opened /// is proportional to the depth of the directory tree traversed. pub fn max_open(mut self, n: usize) -> Self { self.walker = self.walker.max_open(n); self } /// Set a function for sorting directory entries. /// /// If a compare function is set, the resulting iterator will return all /// paths in sorted order. The compare function will be called to compare /// entries from the same directory. pub fn sort_by(mut self, cmp: F) -> Self where F: FnMut(&DirEntry, &DirEntry) -> Ordering + Send + Sync + 'static, { self.walker = self.walker.sort_by(cmp); self } /// Yield a directory's contents before the directory itself. By default, /// this is disabled. /// /// When `yes` is `false` (as is the default), the directory is yielded /// before its contents are read. This is useful when, e.g. you want to /// skip processing of some directories. /// /// When `yes` is `true`, the iterator yields the contents of a directory /// before yielding the directory itself. This is useful when, e.g. you /// want to recursively delete a directory. pub fn contents_first(mut self, yes: bool) -> Self { self.walker = self.walker.contents_first(yes); self } /// Toggle whether the globs should be matched case insensitively or not. /// /// This is disabled by default. pub fn case_insensitive(mut self, yes: bool) -> Self { self.case_insensitive = yes; self } /// Toggle filtering by file type. /// `FileType` can be an OR of several types. /// /// Note that not all file-types can be whitelisted by this filter (e.g. char-devices, fifos, etc.) pub fn file_type(mut self, file_type: FileType) -> Self { self.file_type = Some(file_type); self } /// Finalize and build a `GlobWalker` instance. pub fn build(self) -> Result { let mut builder = OverrideBuilder::new(self.root); builder .case_insensitive(self.case_insensitive) .map_err(GlobError)?; for pattern in self.patterns { builder.add(pattern.as_ref()).map_err(GlobError)?; } Ok(GlobWalker { ignore: builder.build().map_err(GlobError)?, walker: self.walker.into_iter(), file_type_filter: self.file_type, }) } } /// An iterator which emits glob-matched patterns. /// /// An instance of this type must be constructed through `GlobWalker`, /// which uses a builder-style pattern. /// /// The order of the yielded paths is undefined, unless specified by the user /// using `GlobWalker::sort_by`. pub struct GlobWalker { ignore: Override, walker: walkdir::IntoIter, file_type_filter: Option, } impl Iterator for GlobWalker { type Item = Result; // Possible optimization - Do not descend into directory that will never be a match fn next(&mut self) -> Option { let mut skip_dir = false; // The outer loop allows us to avoid multiple mutable borrows on `self.walker` when // we want to skip. 'skipper: loop { if skip_dir { self.walker.skip_current_dir(); } // The inner loop just advances the iterator until a match is found. for entry in &mut self.walker { match entry { Ok(e) => { let is_dir = e.file_type().is_dir(); let file_type = if e.file_type().is_dir() { Some(FileType::DIR) } else if e.file_type().is_file() { Some(FileType::FILE) } else if e.file_type().is_symlink() { Some(FileType::SYMLINK) } else { None }; let file_type_matches = match (self.file_type_filter, file_type) { (None, _) => true, (Some(_), None) => false, (Some(filter), Some(actual)) => filter.contains(actual), }; // Strip the common base directory so that the matcher will be // able to recognize the file name. // `unwrap` here is safe, since walkdir returns the files with relation // to the given base-dir. let path = e .path() .strip_prefix(self.ignore.path()) .unwrap() .to_owned(); // The path might be empty after stripping if the current base-directory is matched. if let Some("") = path.to_str() { continue 'skipper; } match self.ignore.matched(path, is_dir) { Match::Whitelist(_) if file_type_matches => return Some(Ok(e)), // If the directory is ignored, quit the iterator loop and // skip-out of this directory. Match::Ignore(_) if is_dir => { skip_dir = true; continue 'skipper; } _ => {} } } Err(e) => { return Some(Err(e)); } } } break; } None } } /// Construct a new `GlobWalkerBuilder` with a glob pattern. /// /// When iterated, the current directory will be recursively searched for paths /// matching `pattern`, unless the pattern specifies an absolute path. pub fn glob_builder>(pattern: S) -> GlobWalkerBuilder { // Check to see if the pattern starts with an absolute path let path_pattern: PathBuf = pattern.as_ref().into(); if path_pattern.is_absolute() { // If the pattern is an absolute path, split it into the longest base and a pattern. let mut base = PathBuf::new(); let mut pattern = PathBuf::new(); let mut globbing = false; // All `to_str().unwrap()` calls should be valid since the input is a string. for c in path_pattern.components() { let os = c.as_os_str().to_str().unwrap(); for c in &["*", "{", "}"][..] { if os.contains(c) { globbing = true; break; } } if globbing { pattern.push(c); } else { base.push(c); } } let pat = pattern.to_str().unwrap(); if cfg!(windows) { GlobWalkerBuilder::new(base.to_str().unwrap(), pat.replace("\\", "/")) } else { GlobWalkerBuilder::new(base.to_str().unwrap(), pat) } } else { // If the pattern is relative, start searching from the current directory. GlobWalkerBuilder::new(".", pattern) } } /// Construct a new `GlobWalker` with a glob pattern. /// /// When iterated, the current directory will be recursively searched for paths /// matching `pattern`, unless the pattern specifies an absolute path. pub fn glob>(pattern: S) -> Result { glob_builder(pattern).build() } #[cfg(test)] mod tests { use super::*; use std::fs::{create_dir_all, File}; use tempdir::TempDir; fn touch(dir: &TempDir, names: &[&str]) { for name in names { let name = normalize_path_sep(name); File::create(dir.path().join(name)).expect("Failed to create a test file"); } } fn normalize_path_sep>(s: S) -> String { s.as_ref() .replace("[/]", if cfg!(windows) { "\\" } else { "/" }) } fn equate_to_expected(g: GlobWalker, mut expected: Vec, dir_path: &Path) { for matched_file in g.into_iter().filter_map(Result::ok) { let path = matched_file .path() .strip_prefix(dir_path) .unwrap() .to_str() .unwrap(); let path = normalize_path_sep(path); let del_idx = if let Some(idx) = expected.iter().position(|n| &path == n) { idx } else { panic!("Iterated file is unexpected: {}", path); }; expected.remove(del_idx); } // Not equating `.len() == 0` so that the assertion output // will contain the extra files let empty: &[&str] = &[][..]; assert_eq!(expected, empty); } #[test] fn test_absolute_path() { let dir = TempDir::new("globset_walkdir").expect("Failed to create temporary folder"); let dir_path = dir.path().canonicalize().unwrap(); touch(&dir, &["a.rs", "a.jpg", "a.png", "b.docx"][..]); let expected = ["a.jpg", "a.png"].iter().map(ToString::to_string).collect(); let mut cwd = dir_path.clone(); cwd.push("*.{png,jpg,gif}"); let glob = glob(cwd.to_str().unwrap().to_owned()).unwrap(); equate_to_expected(glob, expected, &dir_path); } #[test] fn test_new() { let dir = TempDir::new("globset_walkdir").expect("Failed to create temporary folder"); let dir_path = dir.path(); touch(&dir, &["a.rs", "a.jpg", "a.png", "b.docx"][..]); let expected = ["a.jpg", "a.png"].iter().map(ToString::to_string).collect(); let g = GlobWalkerBuilder::new(dir_path, "*.{png,jpg,gif}") .build() .unwrap(); equate_to_expected(g, expected, dir_path); } #[test] fn test_from_patterns() { let dir = TempDir::new("globset_walkdir").expect("Failed to create temporary folder"); let dir_path = dir.path(); create_dir_all(dir_path.join("src/some_mod")).expect(""); create_dir_all(dir_path.join("tests")).expect(""); create_dir_all(dir_path.join("contrib")).expect(""); touch( &dir, &[ "a.rs", "b.rs", "avocado.rs", "lib.c", "src[/]hello.rs", "src[/]world.rs", "src[/]some_mod[/]unexpected.rs", "src[/]cruel.txt", "contrib[/]README.md", "contrib[/]README.rst", "contrib[/]lib.rs", ][..], ); let expected: Vec<_> = [ "src[/]some_mod[/]unexpected.rs", "src[/]world.rs", "src[/]hello.rs", "lib.c", "contrib[/]lib.rs", "contrib[/]README.md", "contrib[/]README.rst", ] .iter() .map(normalize_path_sep) .collect(); let patterns = ["src/**/*.rs", "*.c", "**/lib.rs", "**/*.{md,rst}"]; let glob = GlobWalkerBuilder::from_patterns(dir_path, &patterns) .build() .unwrap(); equate_to_expected(glob, expected, dir_path); } #[test] fn test_case_insensitive_matching() { let dir = TempDir::new("globset_walkdir").expect("Failed to create temporary folder"); let dir_path = dir.path(); create_dir_all(dir_path.join("src/some_mod")).expect(""); create_dir_all(dir_path.join("tests")).expect(""); create_dir_all(dir_path.join("contrib")).expect(""); touch( &dir, &[ "a.rs", "b.rs", "avocado.RS", "lib.c", "src[/]hello.RS", "src[/]world.RS", "src[/]some_mod[/]unexpected.rs", "src[/]cruel.txt", "contrib[/]README.md", "contrib[/]README.rst", "contrib[/]lib.rs", ][..], ); let expected: Vec<_> = [ "src[/]some_mod[/]unexpected.rs", "src[/]hello.RS", "src[/]world.RS", "lib.c", "contrib[/]lib.rs", "contrib[/]README.md", "contrib[/]README.rst", ] .iter() .map(normalize_path_sep) .collect(); let patterns = ["src/**/*.rs", "*.c", "**/lib.rs", "**/*.{md,rst}"]; let glob = GlobWalkerBuilder::from_patterns(dir_path, &patterns) .case_insensitive(true) .build() .unwrap(); equate_to_expected(glob, expected, dir_path); } #[test] fn test_match_dir() { let dir = TempDir::new("globset_walkdir").expect("Failed to create temporary folder"); let dir_path = dir.path(); create_dir_all(dir_path.join("mod")).expect(""); touch( &dir, &[ "a.png", "b.png", "c.png", "mod[/]a.png", "mod[/]b.png", "mod[/]c.png", ][..], ); let expected: Vec<_> = ["mod"].iter().map(normalize_path_sep).collect(); let glob = GlobWalkerBuilder::new(dir_path, "mod").build().unwrap(); equate_to_expected(glob, expected, dir_path); } #[test] fn test_blacklist() { let dir = TempDir::new("globset_walkdir").expect("Failed to create temporary folder"); let dir_path = dir.path(); create_dir_all(dir_path.join("src/some_mod")).expect(""); create_dir_all(dir_path.join("tests")).expect(""); create_dir_all(dir_path.join("contrib")).expect(""); touch( &dir, &[ "a.rs", "b.rs", "avocado.rs", "lib.c", "src[/]hello.rs", "src[/]world.rs", "src[/]some_mod[/]unexpected.rs", "src[/]cruel.txt", "contrib[/]README.md", "contrib[/]README.rst", "contrib[/]lib.rs", ][..], ); let expected: Vec<_> = [ "src[/]some_mod[/]unexpected.rs", "src[/]hello.rs", "lib.c", "contrib[/]lib.rs", "contrib[/]README.md", "contrib[/]README.rst", ] .iter() .map(normalize_path_sep) .collect(); let patterns = [ "src/**/*.rs", "*.c", "**/lib.rs", "**/*.{md,rst}", "!world.rs", ]; let glob = GlobWalkerBuilder::from_patterns(dir_path, &patterns) .build() .unwrap(); equate_to_expected(glob, expected, dir_path); } #[test] fn test_blacklist_dir() { let dir = TempDir::new("globset_walkdir").expect("Failed to create temporary folder"); let dir_path = dir.path(); create_dir_all(dir_path.join("Pictures")).expect(""); touch( &dir, &[ "a.png", "b.png", "c.png", "Pictures[/]a.png", "Pictures[/]b.png", "Pictures[/]c.png", ][..], ); let expected: Vec<_> = ["a.png", "b.png", "c.png"] .iter() .map(normalize_path_sep) .collect(); let patterns = ["*.{png,jpg,gif}", "!Pictures"]; let glob = GlobWalkerBuilder::from_patterns(dir_path, &patterns) .build() .unwrap(); equate_to_expected(glob, expected, dir_path); } #[test] fn test_glob_with_double_star_pattern() { let dir = TempDir::new("globset_walkdir").expect("Failed to create temporary folder"); let dir_path = dir.path().canonicalize().unwrap(); touch(&dir, &["a.rs", "a.jpg", "a.png", "b.docx"][..]); let expected = ["a.jpg", "a.png"].iter().map(ToString::to_string).collect(); let mut cwd = dir_path.clone(); cwd.push("**"); cwd.push("*.{png,jpg,gif}"); let glob = glob(cwd.to_str().unwrap().to_owned()).unwrap(); equate_to_expected(glob, expected, &dir_path); } #[test] fn test_glob_single_star() { let dir = TempDir::new("globset_walkdir").expect("Failed to create temporary folder"); let dir_path = dir.path(); create_dir_all(dir_path.join("Pictures")).expect(""); create_dir_all(dir_path.join("Pictures").join("b")).expect(""); touch( &dir, &[ "a.png", "b.png", "c.png", "Pictures[/]a.png", "Pictures[/]b.png", "Pictures[/]c.png", "Pictures[/]b[/]c.png", "Pictures[/]b[/]c.png", "Pictures[/]b[/]c.png", ][..], ); let glob = GlobWalkerBuilder::new(dir_path, "*") .sort_by(|a, b| a.path().cmp(b.path())) .build() .unwrap(); let expected = ["Pictures", "a.png", "b.png", "c.png"] .iter() .map(ToString::to_string) .collect(); equate_to_expected(glob, expected, dir_path); } #[test] fn test_file_type() { let dir = TempDir::new("globset_walkdir").expect("Failed to create temporary folder"); let dir_path = dir.path(); create_dir_all(dir_path.join("Pictures")).expect(""); create_dir_all(dir_path.join("Pictures").join("b")).expect(""); touch( &dir, &[ "a.png", "b.png", "c.png", "Pictures[/]a.png", "Pictures[/]b.png", "Pictures[/]c.png", "Pictures[/]b[/]c.png", "Pictures[/]b[/]c.png", "Pictures[/]b[/]c.png", ][..], ); let glob = GlobWalkerBuilder::new(dir_path, "*") .sort_by(|a, b| a.path().cmp(b.path())) .file_type(FileType::DIR) .build() .unwrap(); let expected = ["Pictures"].iter().map(ToString::to_string).collect(); equate_to_expected(glob, expected, dir_path); let glob = GlobWalkerBuilder::new(dir_path, "*") .sort_by(|a, b| a.path().cmp(b.path())) .file_type(FileType::FILE) .build() .unwrap(); let expected = ["a.png", "b.png", "c.png"] .iter() .map(ToString::to_string) .collect(); equate_to_expected(glob, expected, dir_path); } } globwalk-0.8.1/tests/docs.rs010064400017500001750000000004331376375613200141600ustar 00000000000000extern crate docmatic; #[test] fn readme_test() { let readme = std::path::Path::new(file!()).canonicalize().unwrap(); let readme = readme.parent().unwrap().parent().unwrap().join("README.md"); let readme = readme.to_str().unwrap(); docmatic::assert_file(readme); }