use crate::host::Access;
use crate::service::Permit;
use std::fs::File;
use std::io;
use std::path::Path;
use std::time::SystemTime;
fn not_yet() -> io::Error {
io::Error::new(
io::ErrorKind::Unsupported,
"Pitboard does not change files on Windows yet",
)
}
pub(crate) fn create_private_dir(_: Permit, _path: &Path) -> io::Result<()> {
Err(not_yet())
}
pub(crate) fn create_private(_: Permit, _path: &Path) -> io::Result<File> {
Err(not_yet())
}
pub(crate) fn open_private_append(_: Permit, _path: &Path) -> io::Result<File> {
Err(not_yet())
}
pub(crate) fn open_private_lock(_: Permit, _path: &Path) -> io::Result<File> {
Err(not_yet())
}
pub(crate) fn copy_access(_: Permit, _existing: &Path, _temp: &Path) -> io::Result<()> {
Err(not_yet())
}
pub(crate) fn sync_dir(_dir: &Path) {}
pub(crate) fn touch_dir(_: Permit, _path: &Path, _at: SystemTime) -> io::Result<()> {
Err(not_yet())
}
pub(crate) fn create_dir_all(_: Permit, _path: &Path) -> io::Result<()> {
Err(not_yet())
}
pub(crate) fn create_dir(_: Permit, _path: &Path) -> io::Result<()> {
Err(not_yet())
}
pub(crate) fn copy(_: Permit, _from: &Path, _to: &Path) -> io::Result<u64> {
Err(not_yet())
}
pub(crate) fn rename(_: Permit, _from: &Path, _to: &Path) -> io::Result<()> {
Err(not_yet())
}
pub(crate) fn remove_file(_: Permit, _path: &Path) -> io::Result<()> {
Err(not_yet())
}
pub(crate) fn remove_dir(_: Permit, _path: &Path) -> io::Result<()> {
Err(not_yet())
}
pub(crate) fn remove_dir_all(_: Permit, _path: &Path) -> io::Result<()> {
Err(not_yet())
}
pub fn access(_path: &Path) -> Option<Access> {
None
}
#[cfg(any(test, feature = "test-support"))]
pub mod testing {
use std::io;
use std::path::Path;
fn not_yet() -> io::Error {
io::Error::new(
io::ErrorKind::Unsupported,
"a file's access on Windows is set by W15",
)
}
pub fn open_to_others(_path: &Path) -> io::Result<()> {
Err(not_yet())
}
pub fn make_private(_path: &Path) -> io::Result<()> {
Err(not_yet())
}
pub fn is_private(_path: &Path) -> io::Result<bool> {
Err(not_yet())
}
pub fn read_only_for_owner(_path: &Path) -> io::Result<()> {
Err(not_yet())
}
pub fn deny_reading(_path: &Path) -> io::Result<()> {
Err(not_yet())
}
pub fn make_runnable(_path: &Path) -> io::Result<()> {
Err(not_yet())
}
pub fn deny_running(_path: &Path) -> io::Result<()> {
Err(not_yet())
}
pub fn deny_changes(_dir: &Path) -> io::Result<()> {
Err(not_yet())
}
pub fn allow_changes(_dir: &Path) -> io::Result<()> {
Err(not_yet())
}
pub fn link(_target: &Path, _at: &Path) -> io::Result<()> {
Err(not_yet())
}
pub fn link_dir(_target: &Path, _at: &Path) -> io::Result<()> {
Err(not_yet())
}
}
#[cfg(test)]
mod tests {
use super::testing;
use std::io;
use std::path::Path;
#[test]
fn every_change_to_a_files_access_waits_for_w15() {
let path = Path::new("never-made");
let answers: [(&str, io::Result<()>); 10] = [
("open_to_others", testing::open_to_others(path)),
("make_private", testing::make_private(path)),
("read_only_for_owner", testing::read_only_for_owner(path)),
("deny_reading", testing::deny_reading(path)),
("make_runnable", testing::make_runnable(path)),
("deny_running", testing::deny_running(path)),
("deny_changes", testing::deny_changes(path)),
("allow_changes", testing::allow_changes(path)),
("link", testing::link(path, path)),
("link_dir", testing::link_dir(path, path)),
];
for (what, answer) in answers {
let refused = answer.expect_err(what);
assert_eq!(refused.kind(), io::ErrorKind::Unsupported, "{what}");
}
let private = testing::is_private(path).expect_err("is_private");
assert_eq!(private.kind(), io::ErrorKind::Unsupported);
assert!(!path.exists(), "nothing was made");
}
}