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

Add necessary conditional compilation cfgs #1752

Merged
merged 2 commits into from
Aug 3, 2022
Merged
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
17 changes: 7 additions & 10 deletions crates/resolver/src/hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
use std::collections::HashMap;
use std::io;
use std::path::Path;
#[cfg(any(unix, windows))]
use std::str::FromStr;
use std::sync::Arc;

use proto::op::Query;
use proto::rr::{Name, RecordType};
#[cfg(any(unix, windows))]
use proto::rr::{RData, Record};
use tracing::warn;

Expand All @@ -35,10 +33,17 @@ impl Hosts {
/// Creates a new configuration from the system hosts file,
/// only works for Windows and Unix-like OSes,
/// will return empty configuration on others
#[cfg(any(unix, windows))]
pub fn new() -> Self {
read_hosts_conf(hosts_path()).unwrap_or_default()
}

/// Creates a default configuration for non Windows or Unix-like OSes
#[cfg(not(any(unix, windows)))]
pub fn new() -> Self {
djc marked this conversation as resolved.
Show resolved Hide resolved
Hosts::default()
}

/// Look up the addresses for the given host from the system hosts file.
pub fn lookup_static_host(&self, query: &Query) -> Option<Lookup> {
if !self.by_name.is_empty() {
Expand Down Expand Up @@ -175,14 +180,6 @@ pub(crate) fn read_hosts_conf<P: AsRef<Path>>(path: P) -> io::Result<Hosts> {
Hosts::default().read_hosts_conf(file)
}

#[cfg(not(any(unix, windows)))]
pub fn read_hosts_conf<P: AsRef<Path>>(_path: P) -> io::Result<Hosts> {
Err(io::Error::new(
io::ErrorKind::Other,
"Only Windows or Unix-like hosts file is supported".to_string(),
))
}

#[cfg(any(unix, windows))]
#[cfg(test)]
mod tests {
Expand Down