Skip to content

Commit

Permalink
🚚 Move some cli private fs utilities to pna public api
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanTsune committed Feb 21, 2024
1 parent bfb893a commit 6af3c4b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
20 changes: 2 additions & 18 deletions cli/src/utils/fs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub(crate) use pna::fs::*;
use std::path::Path;
use std::{fs, io, os};
use std::{fs, io};

#[inline]
pub(crate) fn remove<P: AsRef<Path>>(path: P) -> io::Result<()> {
Expand All @@ -10,20 +11,3 @@ pub(crate) fn remove<P: AsRef<Path>>(path: P) -> io::Result<()> {
fs::remove_file(path)
}
}

#[cfg(unix)]
#[inline]
pub(crate) fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<()> {
os::unix::fs::symlink(original, link)
}

#[cfg(windows)]
#[inline]
pub(crate) fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<()> {
let original = original.as_ref();
if original.is_dir() {
os::windows::fs::symlink_dir(original, link)
} else {
os::windows::fs::symlink_file(original, link)
}
}
19 changes: 19 additions & 0 deletions pna/src/fs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::path::Path;
use std::{io, os};

#[cfg(unix)]
#[inline]
pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<()> {
os::unix::fs::symlink(original, link)
}

#[cfg(windows)]
#[inline]
pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Result<()> {
let original = original.as_ref();
if original.is_dir() {
os::windows::fs::symlink_dir(original, link)
} else {
os::windows::fs::symlink_file(original, link)
}
}
4 changes: 2 additions & 2 deletions pna/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod fs;

pub use libpna::*;
#[cfg(feature = "portable-network-archive")]
pub use portable_network_archive::*;

0 comments on commit 6af3c4b

Please sign in to comment.