Skip to content

Commit

Permalink
Fix: target_family unix means also macos and linux; use BSD target_os
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Jun 21, 2021
1 parent 04cafc4 commit c78fc58
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 51 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ pretty_assertions = "0.7.2"
github-actions = []
with-containers = []

[target."cfg(any(target_family = \"unix\", target_os = \"macos\", target_os = \"linux\"))"]
[target."cfg(any(target_family = \"unix\", target_os = \"macos\", target_os = \"linux\"))".dependencies]
[target."cfg(target_family = \"unix\")"]
[target."cfg(target_family = \"unix\")".dependencies]
users = "0.11.0"

[target."cfg(any(target_os = \"windows\", target_os = \"macos\"))"]
Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ mod tests {
PathBuf::from(cfg.user_interface.text_editor.file_name().unwrap()), // NOTE: since edit 0.1.3 real path is used
PathBuf::from("vim.EXE")
);
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
assert_eq!(
PathBuf::from(cfg.user_interface.text_editor.file_name().unwrap()), // NOTE: since edit 0.1.3 real path is used
PathBuf::from("vim")
Expand Down
2 changes: 1 addition & 1 deletion src/filetransfer/ftp_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl FtpFileTransfer {
PathBuf::from(path_slash::PathExt::to_slash_lossy(p).as_str())
}

#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
fn resolve(p: &Path) -> PathBuf {
p.to_path_buf()
}
Expand Down
2 changes: 1 addition & 1 deletion src/filetransfer/scp_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl ScpFileTransfer {
PathBuf::from(path_slash::PathExt::to_slash_lossy(p).as_str())
}

#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
fn resolve(p: &Path) -> PathBuf {
p.to_path_buf()
}
Expand Down
20 changes: 10 additions & 10 deletions src/fs/explorer/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
// Deps
extern crate bytesize;
extern crate regex;
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
extern crate users;
// Locals
use super::FsEntry;
use crate::utils::fmt::{fmt_path_elide, fmt_pex, fmt_time};
// Ext
use bytesize::ByteSize;
use regex::Regex;
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
use users::{get_group_by_gid, get_user_by_uid};
// Types
// FmtCallback: Formatter, fsentry: &FsEntry, cur_str, prefix, length, extra
Expand Down Expand Up @@ -251,7 +251,7 @@ impl Formatter {
_fmt_extra: Option<&String>,
) -> String {
// Get username
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
let group: String = match fsentry.get_group() {
Some(gid) => match get_group_by_gid(gid) {
Some(user) => user.name().to_string_lossy().to_string(),
Expand Down Expand Up @@ -431,7 +431,7 @@ impl Formatter {
_fmt_extra: Option<&String>,
) -> String {
// Get username
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
let username: String = match fsentry.get_user() {
Some(uid) => match get_user_by_uid(uid) {
Some(user) => user.name().to_string_lossy().to_string(),
Expand Down Expand Up @@ -605,7 +605,7 @@ mod tests {
group: Some(0), // UNIX only
unix_pex: Some((6, 4, 4)), // UNIX only
});
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
assert_eq!(
formatter.fmt(&entry),
format!(
Expand Down Expand Up @@ -636,7 +636,7 @@ mod tests {
group: Some(0), // UNIX only
unix_pex: Some((6, 4, 4)), // UNIX only
});
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
assert_eq!(
formatter.fmt(&entry),
format!(
Expand Down Expand Up @@ -667,7 +667,7 @@ mod tests {
group: Some(0), // UNIX only
unix_pex: None, // UNIX only
});
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
assert_eq!(
formatter.fmt(&entry),
format!(
Expand Down Expand Up @@ -698,7 +698,7 @@ mod tests {
group: Some(0), // UNIX only
unix_pex: None, // UNIX only
});
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
assert_eq!(
formatter.fmt(&entry),
format!(
Expand Down Expand Up @@ -734,7 +734,7 @@ mod tests {
group: Some(0), // UNIX only
unix_pex: Some((7, 5, 5)), // UNIX only
});
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
assert_eq!(
formatter.fmt(&entry),
format!(
Expand Down Expand Up @@ -763,7 +763,7 @@ mod tests {
group: Some(0), // UNIX only
unix_pex: None, // UNIX only
});
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
assert_eq!(
formatter.fmt(&entry),
format!(
Expand Down
2 changes: 1 addition & 1 deletion src/fs/explorer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ mod tests {
group: Some(0), // UNIX only
unix_pex: Some((6, 4, 4)), // UNIX only
});
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
assert_eq!(
explorer.fmt_file(&entry),
format!(
Expand Down
56 changes: 28 additions & 28 deletions src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ use std::time::SystemTime;
use thiserror::Error;
use wildmatch::WildMatch;
// Metadata ext
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
use std::fs::set_permissions;
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
use std::os::unix::fs::{MetadataExt, PermissionsExt};

// Locals
Expand Down Expand Up @@ -439,7 +439,7 @@ impl Localhost {
/// ### stat
///
/// Stat file and create a FsEntry
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
pub fn stat(&self, path: &Path) -> Result<FsEntry, HostError> {
info!("Stating file {}", path.display());
let path: PathBuf = self.to_abs_path(path);
Expand Down Expand Up @@ -605,7 +605,7 @@ impl Localhost {
/// ### chmod
///
/// Change file mode to file, according to UNIX permissions
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
pub fn chmod(&self, path: &Path, pex: (u8, u8, u8)) -> Result<(), HostError> {
let path: PathBuf = self.to_abs_path(path);
// Get metadta
Expand Down Expand Up @@ -790,7 +790,7 @@ impl Localhost {
/// ### u32_to_mode
///
/// Return string with format xxxxxx to tuple of permissions (user, group, others)
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
fn u32_to_mode(&self, mode: u32) -> (u8, u8, u8) {
let user: u8 = ((mode >> 6) & 0x7) as u8;
let group: u8 = ((mode >> 3) & 0x7) as u8;
Expand All @@ -801,7 +801,7 @@ impl Localhost {
/// mode_to_u32
///
/// Convert owner,group,others to u32
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
fn mode_to_u32(&self, mode: (u8, u8, u8)) -> u32 {
((mode.0 as u32) << 6) + ((mode.1 as u32) << 3) + mode.2 as u32
}
Expand All @@ -826,17 +826,17 @@ impl Localhost {
mod tests {

use super::*;
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
use crate::utils::test_helpers::{create_sample_file, make_fsentry};
use crate::utils::test_helpers::{make_dir_at, make_file_at};

use pretty_assertions::assert_eq;
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
use std::fs::File;
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
use std::io::Write;

#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
use std::os::unix::fs::{symlink, PermissionsExt};

#[test]
Expand All @@ -848,7 +848,7 @@ mod tests {
}

#[test]
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
fn test_host_localhost_new() {
let host: Localhost = Localhost::new(PathBuf::from("/dev")).ok().unwrap();
assert_eq!(host.wrkdir, PathBuf::from("/dev"));
Expand Down Expand Up @@ -884,14 +884,14 @@ mod tests {
}

#[test]
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
fn test_host_localhost_pwd() {
let host: Localhost = Localhost::new(PathBuf::from("/dev")).ok().unwrap();
assert_eq!(host.pwd(), PathBuf::from("/dev"));
}

#[test]
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
fn test_host_localhost_list_files() {
let host: Localhost = Localhost::new(PathBuf::from("/dev")).ok().unwrap();
// Scan dir
Expand All @@ -904,7 +904,7 @@ mod tests {
}

#[test]
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
fn test_host_localhost_change_dir() {
let mut host: Localhost = Localhost::new(PathBuf::from("/dev")).ok().unwrap();
let new_dir: PathBuf = PathBuf::from("/dev");
Expand All @@ -920,7 +920,7 @@ mod tests {
}

#[test]
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
#[should_panic]
fn test_host_localhost_change_dir_failed() {
let mut host: Localhost = Localhost::new(PathBuf::from("/dev")).ok().unwrap();
Expand All @@ -929,7 +929,7 @@ mod tests {
}

#[test]
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
fn test_host_localhost_open_read() {
let host: Localhost = Localhost::new(PathBuf::from("/dev")).ok().unwrap();
// Create temp file
Expand All @@ -938,7 +938,7 @@ mod tests {
}

#[test]
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
#[should_panic]
fn test_host_localhost_open_read_err_no_such_file() {
let host: Localhost = Localhost::new(PathBuf::from("/dev")).ok().unwrap();
Expand All @@ -959,7 +959,7 @@ mod tests {
}

#[test]
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
fn test_host_localhost_open_write() {
let host: Localhost = Localhost::new(PathBuf::from("/dev")).ok().unwrap();
// Create temp file
Expand All @@ -978,7 +978,7 @@ mod tests {
assert!(host.open_file_write(file.path()).is_err());
}

#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
#[test]
fn test_host_localhost_symlinks() {
let tmpdir: tempfile::TempDir = tempfile::TempDir::new().unwrap();
Expand Down Expand Up @@ -1026,7 +1026,7 @@ mod tests {
}

#[test]
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
fn test_host_localhost_mkdir() {
let tmpdir: tempfile::TempDir = tempfile::TempDir::new().unwrap();
let mut host: Localhost = Localhost::new(PathBuf::from(tmpdir.path())).ok().unwrap();
Expand All @@ -1051,7 +1051,7 @@ mod tests {
}

#[test]
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
fn test_host_localhost_remove() {
let tmpdir: tempfile::TempDir = tempfile::TempDir::new().unwrap();
// Create sample file
Expand Down Expand Up @@ -1080,7 +1080,7 @@ mod tests {
}

#[test]
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
fn test_host_localhost_rename() {
let tmpdir: tempfile::TempDir = tempfile::TempDir::new().unwrap();
// Create sample file
Expand Down Expand Up @@ -1108,7 +1108,7 @@ mod tests {
.is_err());
}

#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
#[test]
fn test_host_chmod() {
let tmpdir: tempfile::TempDir = tempfile::TempDir::new().unwrap();
Expand All @@ -1127,7 +1127,7 @@ mod tests {
.is_err());
}

#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
#[test]
fn test_host_copy_file_absolute() {
let tmpdir: tempfile::TempDir = tempfile::TempDir::new().unwrap();
Expand Down Expand Up @@ -1157,7 +1157,7 @@ mod tests {
.is_err());
}

#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
#[test]
fn test_host_copy_file_relative() {
let tmpdir: tempfile::TempDir = tempfile::TempDir::new().unwrap();
Expand All @@ -1179,7 +1179,7 @@ mod tests {
assert_eq!(host.files.len(), 2);
}

#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
#[test]
fn test_host_copy_directory_absolute() {
let tmpdir: tempfile::TempDir = tempfile::TempDir::new().unwrap();
Expand Down Expand Up @@ -1210,7 +1210,7 @@ mod tests {
assert!(host.stat(test_file_path.as_path()).is_ok());
}

#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
#[test]
fn test_host_copy_directory_relative() {
let tmpdir: tempfile::TempDir = tempfile::TempDir::new().unwrap();
Expand Down Expand Up @@ -1245,7 +1245,7 @@ mod tests {
let tmpdir: tempfile::TempDir = tempfile::TempDir::new().unwrap();
let host: Localhost = Localhost::new(PathBuf::from(tmpdir.path())).ok().unwrap();
// Execute
#[cfg(any(target_family = "unix", target_os = "macos", target_os = "linux"))]
#[cfg(target_family = "unix")]
assert_eq!(host.exec("echo 5").ok().unwrap().as_str(), "5\n");
#[cfg(target_os = "windows")]
assert_eq!(host.exec("echo 5").ok().unwrap().as_str(), "5\r\n");
Expand Down
14 changes: 12 additions & 2 deletions src/system/bookmarks_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ impl BookmarksClient {
}
};
// Make a key storage (linux / unix)
#[cfg(any(target_os = "linux", target_family = "unix"))]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "netbsd",
target_os = "netbsd"
))]
let (key_storage, service_id): (Box<dyn KeyStorage>, &str) = {
#[cfg(not(test))]
let app_name: &str = "bookmarks";
Expand Down Expand Up @@ -446,7 +451,12 @@ mod tests {
}

#[test]
#[cfg(any(target_family = "unix", target_os = "linux"))]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "netbsd",
target_os = "netbsd"
))]
fn test_system_bookmarks_new_err() {
assert!(BookmarksClient::new(
Path::new("/tmp/oifoif/omar"),
Expand Down
Loading

0 comments on commit c78fc58

Please sign in to comment.